“Filterarray nach Schlüsselwort” Code-Antworten

Filter in der Array -Funktion

const persons = [
  {name:"Shirshak",gender:"male"},
  {name:"Amelia",gender:"female"},
  {name:"Amand",gender:"male"}
]
//filter return all objects in array
let male = persons.filter(function(person){
return person.gender==='male'
})
console.log(male) //[{name:"Shirshak",gender:"male"},{name:"Amand",gender:"male"}]

//find return first object that match condition
let female = persons.find(function(person){
return person.gender==='female'
})
Shirshak kandel

Filterarray nach Schlüsselwort

var data = [
  {email: "[email protected]",nama:"User A", Level:"Super Admin"},
  {email: "[email protected]",nama:"User B", Level:"Super Admin"},
  {email: "[email protected]",nama:"User C", Level:"Standart"},
  {email: "[email protected]",nama:"User D", Level:"Standart"},
  {email: "[email protected]",nama:"User E", Level:"Admin"},
  {email: "[email protected]",nama:"User F", Level:"Standart"}
];
var filter = "Level";
var keyword = "Standart";

var filteredData = data.filter(function(obj) {
	return obj[filter] === keyword;
});

console.log(filteredData);
Richard

Ähnliche Antworten wie “Filterarray nach Schlüsselwort”

Fragen ähnlich wie “Filterarray nach Schlüsselwort”

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen