I have an array which contains numbers from 0 to 100.
If I click div element there will be one dropdown shown where all these array elements will be shown. but if i type a number in text field eg 0, drop down should show values of array contains[0,10,20,30,40,50,60,70,80,90,100] automatically. eg if we type a number 10, drop down should show values of the array contains [10,100];
Can someone suggest me a logic?
You can use the following function.
//let arr = Array.apply(null, {length: 101}).map(Number.call, Number);
//arr is your array
//num is the number you want to search for
function filterArr(num) {
return arr
.map(i => i.toString())
.filter(i => i.includes(num.toString()))
.map(i => parseInt(i));
}
console.log(filterArr(0));//logs [ 0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100 ]
Hope this helps. As you have not provided any code, you might not be able to use this solution as-is. But the logic should work for you.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.