Arrays are one of the most common things that you’re going to use as a programmer. In this article, I’m going to be covering important JavaScript array methods that are going to make your life as a developer so much easier. As an example, I am going to use a student array of student objects for all of these different array methods.

const students = [
	{name: "sam", age: 26, score: 80},
	{name: "john", age: 25, score: 86},
	{name: "dean", age: 20, score: 78},
	{name: "timothy", age: 18, score: 95},
	{name: "frank", age: 21, score: 67}
] 

1. filter()

So let’s assume that we want to get all of the students in this list whose ages are less than or equal to 24. All we would need to use is the filter method to filter out every student that’s not under 24.

const students = [
	{name: "sam", age: 26, score: 80},
	{name: "john", age: 25, score: 86},
	{name: "dean", age: 20, score: 78},
	{name: "timothy", age: 18, score: 95},
	{name: "frank", age: 21, score: 67}
] 

const filteredStudents = students.filter((students) => {
	//this filter method just takes a single function, which is going to have one parameter of 	student 	which is every student/item in the array
	// we'd need to return a true or false statement on whether or not we want to include them in the 	new array
	return students.age <= 24
	//This line basically stashes all of the students whose ages are less than a 24 in the new 	filteredStudents array
})

console.log(filteredStudents)

//

#front-end-development #software-development #web-development #programming #javascript

Array Methods That Every JavaScript Developer Must Know
2.40 GEEK