Hackerss.com

Hackerss.com is a community of amazing hackers

Hackerss is a community for developers, data scientitst, ethical hackers, hardware enthusiasts or any person that want to learn / share their knowledge of any aspect of digital technology.

Create account Log in
hackerss
hackerss

Posted on

Javascript Example of how to implement twitter typeahead for auto complete


//create a variable to hold the input field
const input = document.querySelector('.input');

//create a variable to hold the output field
const output = document.querySelector('.output');

//create a variable to hold the button
const button = document.querySelector('.button');

//create a variable to hold the array of data
const data = [
  'apple',
  'banana',
  'orange',
  'grape',
  'pear',
  'strawberry',
  'kiwi',
  'mango',
  'watermelon',
  'pineapple',
  'avocado',
  'peach',
  'cherry',
  'coconut',
  'papaya',
  'plum',
  'lemon',
  'lime',
  'grapefruit',
  'guava',
  'lychee',
  'dragonfruit'
];

//create a variable to hold the array of data that is filtered by the input field value
let filteredData = [];

//create a variable to hold the array of data that is filtered by the input field value and is sorted by length of the string in descending order
let sortedData = [];

//create a variable to hold the array of data that is filtered by the input field value and is sorted by length of the string in descending order and is limited to 10 items only. This is used for the output field.
let limitedData = [];
























































































































































Enter fullscreen mode Exit fullscreen mode

Oldest comments (0)