Answers for "array find function javascript"

29

find element in array javascript

const simpleArray = [3, 5, 7, 15];
const objectArray = [{ name: 'John' }, { name: 'Emma' }]

console.log( simpleArray.find(e => e === 7) )
// expected output 7

console.log( simpleArray.find(e => e === 10) )
// expected output undefined

console.log( objectArray.find(e => e.name === 'John') )
// expected output { name: 'John' }
Posted by: Guest on July-06-2020
50

javascript find

const inventory = [
  {name: 'apples', quantity: 2},
  {name: 'cherries', quantity: 8}
  {name: 'bananas', quantity: 0},
  {name: 'cherries', quantity: 5}
  {name: 'cherries', quantity: 15}
  
];

const result = inventory.find( ({ name }) => name === 'cherries' );

console.log(result) // { name: 'cherries', quantity: 5 }
Posted by: Guest on July-11-2020
9

array find

const array1 = [5, 12, 8, 130, 44];

const found = array1.find(element => element > 10);

console.log(found);
// expected output: 12
Posted by: Guest on November-20-2020
9

find method javascript

const inventory = [
  {name: 'apples', quantity: 2},
  {name: 'bananas', quantity: 0},
  {name: 'cherries', quantity: 5}
];

function isCherries(fruit) { 
  return fruit.name === 'cherries';
}

console.log(inventory.find(isCherries)); 
// { name: 'cherries', quantity: 5 }
Posted by: Guest on January-31-2020
1

find in js

The first element that will be found by that function
const f = array1.find(e => e > 10);
Posted by: Guest on August-31-2020
0

search input at array javascript

var people = [
  {
    name: "John Smith",
    url: "http://example.com/johnsmith"
  },
  {
    name: "John Johnson",
    url: "http://example.com/johnjohnson"
  },
  {
    name: "Bob Thompson",
    url: "http://example.com/bobthompson"
  },
  {
    name: "Smith Sanchez",
    url: "http://example.com/smithsanchez"
  },
  {
    name: "Bob Sanchez",
    url: "http://example.com/bobsanchez"
  }
];
$("#search-input").on("keyup", function(){
  var searchFor = $("#search-input").val().toLowerCase();
  var results = [];
  for(var i=0;i<people.length;i++){
    if(people[i].name.toLowerCase().indexOf(searchFor) > -1)
      results.push("<a href='"+people[i].url+"' target='_blank'>"+people[i].name+"</a>")
  }
  if(results.length == 0)
    $("#search-results").html("No Results Found");
  else
    $("#search-results").html(results.join("<br>"));
});
Posted by: Guest on August-19-2020

Code answers related to "array find function javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language