“Array.filter” Ответ

Как отфильтровать массив объектов в 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}]
Handsome Hedgehog

TypeScript Filter Angular Array

ngOnInit() {
  this.booksByStoreID = this.books.filter(
          book => book.store_id === this.store.id);
}
Bad Badger

Фильтр javascript

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

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

console.log(result);

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

Array.filter

// filter(): returns a new array with all elements that pass the test
// If no elements pass the test, an empty array will be returned.

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"]
Inquisitive Iguana

Array.filter

// let arr = [1,2,3]

/*
  filter accepts a callback function, and each value of arr is passed to the 
  callback function. You define the callback function as you would a regular
  function, you're just doing it inside the filter function. filter applies the code 
  in the callback function to each value of arr, and creates a new array based on your 
  callback functions return values. The return value must be a boolean, which denotes whether an element 
  should be keep or not
*/
let filteredArr = arr.filter(function(value){
	return value >= 2
})

// filteredArr is:
// [2,3]
QuietHumility

Array.filter

var newArray = array.filter(function(item)
 {
  return conditional_statement;
 });
Hari krishnan

Ответы похожие на “Array.filter”

Вопросы похожие на “Array.filter”

Смотреть популярные ответы по языку

Смотреть другие языки программирования