osomanden osomanden - 7 months ago 14
Javascript Question

javascript search array, return found keys

I am trying to search for a value in an array and return the found keys with values.

Example:

var arr=['Volvo460', 'Fiat500', 'fiat400', 'volvo C7', 'Saab 95'];
var search = 'volvo';


expected result:

returned_array = ['Volvo460','volvo C7'];


Anyone?

Edit - conformed array ;-)

Pbd Pbd
Answer

var arr = [
   'Volvo460',
   'Fiat500',
   'fiat400',
   'volvo C7',
   'Saab 95'
];
var search = 'volvo',

arr.map(function(v) {
  if(v.toLowerCase().indexOf(search.toLowerCase()) > -1) return v;
});

Comments