does filter return a new array code example

Example 1: how to filter an array of objects in javascript

let arr=[{id:1,title:'A', status:true}, {id:3,title:'B',status:true}, {id:2, title:'xys', status:true}];
//find where title=B
let x = arr.filter((a)=>{if(a.title=='B'){return a}});
console.log(x)//[{id:3,title:'B',status:true}]

Example 2: how the filter() function works javascript

const arr = [1, 2, 3, 4, 5, 6, 7, 8, 9];

const filter = arr.filter((number) => number > 5);
console.log(filter); // [6, 7, 8, 9]

Example 3: javascript array filter elements greater than

function isGreater(element, index, array) { 
   return (element >= 10); 
} 
          
let testElemets = [12, 5, 8, 130, 44].filter(isGreater); 
console.log("Test Value : " + testElemets );

Example 4: array filter

const words = ['spray', 'limit', 'elite', 'exuberant', 'destruction', 'present'];

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

console.log(result);
// expected output: Array ["exuberant", "destruction", "present"]

Example 5: js filter items by index

let newArray = arr.filter(callback(element[, index, [array]])[, thisArg])