Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

array.filter in javascript

//How To Use Array.filter() in JavaScript
//example 1. 
const words = ['spray', 'limit', 'elite', 'exuberant', 'destruction', 'present'];

const result = words.filter(word => word.length < 6);

console.log(result);

//OUTPUT: ['spray', 'limit', 'elite'

//example 2
const numbers = [45, 4, 9, 16, 25];
const over18 = numbers.filter(myFunction);

function myFunction(value, index, array) {
  return value > 18;
}
Source by learn.coderslang.com #
 
PREVIOUS NEXT
Tagged: #javascript
ADD COMMENT
Topic
Name
7+9 =