javascript array filter column code example
Example 1: filter javascript
const arr = [1, 2, 3, 4, 5, 6, 7, 8, 9];
const filter = arr.filter((number) => number > 5);
console.log(filter);
or
const words = ['spray', 'limit', 'elite', 'exuberant', 'destruction', 'present'];
const result = words.filter(word => word.length > 6);
console.log(result);
Example 2: filter 2d array javascript
function filterByPosition(array, number, position) {
return array.filter(innerArray => innerArray[position - 1] !== number);
}
const items = [
[1, 1, 2, 4],
[2, 1, 4, 6],
[5, 6, 4, 1],
[1, 6, 3, 1]
];
const newItems1 = filterByPosition(items, 1, 2);
console.log('Items1:', newItems1);
const newItems2 = filterByPosition(items, 4, 3);
console.log('Items2:', newItems2);