osomanden osomanden - 2 years ago 79
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.


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

expected result:

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


Edit - conformed array ;-)

Pbd Pbd
Answer Source

var arr = [
   'volvo C7',
   'Saab 95'
var search = 'volvo',

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download