Array Some Method
Video
JavaScript Notes
JavaScript
// Array some( ) method
// Wider availability than includes ( )
// functional approach like map, filter, forEach, etc
// returns Boolean when positive match is found, and then stops
let movies = ['Star Wars', 'Star Trek', 'Jaws', 'Jurassic Park', 'Gross Pointe Blank', 'Eternal Sunshine of the Spotless Mind', 'Memento', 'Dog Soldiers', 'The Host', 'Gran Torino', 'Close Encounters of the Third Kind', 'Good Will Hunting', 'Layer Cake', 'Casino Royale', 'Almost Famous'];
let keyword1 = 'Star'; // appears more than once
let keyword2 = 'Cake'; // appears once
let keyword3 = 'Max'; // not in list
let test1 = movies.some(function(title, index ){
console.log(index, title);
return title.indexOf(keyword1) > -1;
} )
let test2 = movies.some(function(title, index ){
console.log(index, title);
return title.indexOf(keyword2) > -1;
} )
let test2 = movies.some(function(title, index ){
console.log(index, title);
return title.indexOf(keyword3) > -1;
} )
Feedback
Submit and view feedback