Shahab Uddin

Shahab Uddin

1588963515

JavaScript array() methods, every JavaScript developer must know

1. push() method allows us to add one or more item at the end of an array.
Example:

let numbers = [1,2,3,4,5];
numbers.push(6); // Adding 6 at the end of the array
console.log(numbers); 
//Output: [1,2,3,4,5,6]

2. pop() method allows us to remove the item from the end of an array.
Example:

let numbers = [1,2,3,4,5];
numbers.pop(); // Removing last item from the array
console.log(numbers); 
//Output: [1,2,3,4]

3. shift() method allow us to remove an item from the front of the array
Example:

let numbers = [1,2,3,4,5];
numbers.shift(); // Removing the first item of the array
console.log(numbers); 
//Output: [2,3,4,5]

4. unshift() method allow us to add new items at the front of the array
Example:

let numbers = [1,2,3,4,5];
numbers.unshift(0); // Adding ‘0’ at the beginning of the array
console.log(numbers);
//Output: [0,1,2,3,4,5]

5. forEach() method will help you to iterate over array’s items.
Example:

let numbers = [1, 2, 3, 4, 5];
numbers.forEach(item => {
	// Let's itrate the given array items and add 1 to each item.
    console.log(item + 1); 
});
//Output: 
2 
3 
4 
5 
6

6. includes() method return booleans to check either your array length includes the specific item passed in the method or not.
Example:

let numbers = [1, 2, 3, 4, 5];
numbers.includes(0); 
//Output: false
numbers.includes(4); 
//Output: true

7. filter() method creates a new array with a subset of elements of the original array.
Example:

Lets create an array object ‘names’ to apply filter()

let names = [
    {name: 'Shahab', age: 35},
    {name: 'Ibaad', age: 10},
    {name: 'Ayaan', age: 30},
    {name: 'Hamad', age: 20},
    {name: 'Pari', age: 22}
];
// Filtering names data by age > 10;
let filterd_items = names.filter(item => item.age > 10);
console.log(filterd_items);

// Output:
0: {name: "Shahab", age: 35}
1: {name: "Ayaan", age: 30}
2: {name: "Hamad", age: 20}
3: {name: "Pari", age: 22}

8. sort() method allows us to sort data and return the elements after changing the positions of the elements in the original array.
The sort() method sorts the array elements in ascending order by default.

let numbers = [1, 5, 2, 0, 40, 3, 10 ];
numbers.sort();
console.log(numbers);
//Output:  [0, 1, 10, 2, 3, 40, 5]

Look at the above output given by sort() method and the output is not as per expected,
To solve this issue, we need to pass a comparison function to the sort() method.

Example:

numbers.sort((a,b) => {
    if(a > b) return 1;
    if(a < b) return -1;
    return 0;
});
console.log(numbers);
//Output: [0, 1, 2, 3, 5, 10, 40]

9. splice() method allows us to delete items in an array, to get result we have to pass two arguments to the splice() method.

Syntax:
Array.splice(position,num);

Example:

let numbers = [1,2,3,4,5];
let deletedNumbs = numbers.splice(0,2);

//The original numbers array now contains only 3 items. i.e: 3,4,5
console.log(numbers); //  [3,4,5]

The new deletedNumbs array contains the deleted items from the original array
console.log(deletedNumbs); // [1, 2]

10. map() method take an array, manipulate its elements, and return a new array by calling the provided function in every element.

Example:

let numbers = [1,2,3,4,5];
Let's multiply each item and get the output doubled
let output = numbers.map(item => item * 2)
console.log(output);
//Output: [2, 4, 6, 8, 10]

#javascript #array #methods #arrowfunction

What is GEEK

Buddha Community

JavaScript array() methods, every JavaScript developer must know

Hire Dedicated JavaScript Developers -Hire JavaScript Developers

It is said that a digital resource a business has must be interactive in nature, so the website or the business app should be interactive. How do you make the app interactive? With the use of JavaScript.

Does your business need an interactive website or app?

Hire Dedicated JavaScript Developer from WebClues Infotech as the developer we offer is highly skilled and expert in what they do. Our developers are collaborative in nature and work with complete transparency with the customers.

The technology used to develop the overall app by the developers from WebClues Infotech is at par with the latest available technology.

Get your business app with JavaScript

For more inquiry click here https://bit.ly/31eZyDZ

Book Free Interview: https://bit.ly/3dDShFg

#hire dedicated javascript developers #hire javascript developers #top javascript developers for hire #hire javascript developer #hire a freelancer for javascript developer #hire the best javascript developers

Ajay Kapoor

1626321063

JS Development Company India | JavaScript Development Services

PixelCrayons: Our JavaScript web development service offers you a feature-packed & dynamic web application that effectively caters to your business challenges and provide you the best RoI. Our JavaScript web development company works on all major frameworks & libraries like Angular, React, Nodejs, Vue.js, to name a few.

With 15+ years of domain expertise, we have successfully delivered 13800+ projects and have successfully garnered 6800+ happy customers with 97%+ client retention rate.

Looking for professional JavaScript web app development services? We provide custom JavaScript development services applying latest version frameworks and libraries to propel businesses to the next level. Our well-defined and manageable JS development processes are balanced between cost, time and quality along with clear communication.

Our JavaScript development companies offers you strict NDA, 100% money back guarantee and agile/DevOps approach.

#javascript development company #javascript development services #javascript web development #javascript development #javascript web development services #javascript web development company

Ajay Kapoor

1623988261

JS Development Company India | JavaScript Development Services

PixelCrayons’ JavaScript web development service offers you a feature-packed & dynamic web application that effectively caters to your business challenges and provide you the best RoI. Our JavaScript web development company works on all major frameworks & libraries like Angular, React, Nodejs, Vue.js, to name a few.

With 15+ years of domain expertise, we have successfully delivered 13800+ projects and have successfully garnered 6800+ happy customers with 97%+ client retention rate.

Javascript Web Development Company

#javascript-web-development-services #javascript-development-company #javascript-development-companies #top-javascript-development-company #best-javascript-development-company

Shahab Uddin

Shahab Uddin

1588963515

JavaScript array() methods, every JavaScript developer must know

1. push() method allows us to add one or more item at the end of an array.
Example:

let numbers = [1,2,3,4,5];
numbers.push(6); // Adding 6 at the end of the array
console.log(numbers); 
//Output: [1,2,3,4,5,6]

2. pop() method allows us to remove the item from the end of an array.
Example:

let numbers = [1,2,3,4,5];
numbers.pop(); // Removing last item from the array
console.log(numbers); 
//Output: [1,2,3,4]

3. shift() method allow us to remove an item from the front of the array
Example:

let numbers = [1,2,3,4,5];
numbers.shift(); // Removing the first item of the array
console.log(numbers); 
//Output: [2,3,4,5]

4. unshift() method allow us to add new items at the front of the array
Example:

let numbers = [1,2,3,4,5];
numbers.unshift(0); // Adding ‘0’ at the beginning of the array
console.log(numbers);
//Output: [0,1,2,3,4,5]

5. forEach() method will help you to iterate over array’s items.
Example:

let numbers = [1, 2, 3, 4, 5];
numbers.forEach(item => {
	// Let's itrate the given array items and add 1 to each item.
    console.log(item + 1); 
});
//Output: 
2 
3 
4 
5 
6

6. includes() method return booleans to check either your array length includes the specific item passed in the method or not.
Example:

let numbers = [1, 2, 3, 4, 5];
numbers.includes(0); 
//Output: false
numbers.includes(4); 
//Output: true

7. filter() method creates a new array with a subset of elements of the original array.
Example:

Lets create an array object ‘names’ to apply filter()

let names = [
    {name: 'Shahab', age: 35},
    {name: 'Ibaad', age: 10},
    {name: 'Ayaan', age: 30},
    {name: 'Hamad', age: 20},
    {name: 'Pari', age: 22}
];
// Filtering names data by age > 10;
let filterd_items = names.filter(item => item.age > 10);
console.log(filterd_items);

// Output:
0: {name: "Shahab", age: 35}
1: {name: "Ayaan", age: 30}
2: {name: "Hamad", age: 20}
3: {name: "Pari", age: 22}

8. sort() method allows us to sort data and return the elements after changing the positions of the elements in the original array.
The sort() method sorts the array elements in ascending order by default.

let numbers = [1, 5, 2, 0, 40, 3, 10 ];
numbers.sort();
console.log(numbers);
//Output:  [0, 1, 10, 2, 3, 40, 5]

Look at the above output given by sort() method and the output is not as per expected,
To solve this issue, we need to pass a comparison function to the sort() method.

Example:

numbers.sort((a,b) => {
    if(a > b) return 1;
    if(a < b) return -1;
    return 0;
});
console.log(numbers);
//Output: [0, 1, 2, 3, 5, 10, 40]

9. splice() method allows us to delete items in an array, to get result we have to pass two arguments to the splice() method.

Syntax:
Array.splice(position,num);

Example:

let numbers = [1,2,3,4,5];
let deletedNumbs = numbers.splice(0,2);

//The original numbers array now contains only 3 items. i.e: 3,4,5
console.log(numbers); //  [3,4,5]

The new deletedNumbs array contains the deleted items from the original array
console.log(deletedNumbs); // [1, 2]

10. map() method take an array, manipulate its elements, and return a new array by calling the provided function in every element.

Example:

let numbers = [1,2,3,4,5];
Let's multiply each item and get the output doubled
let output = numbers.map(item => item * 2)
console.log(output);
//Output: [2, 4, 6, 8, 10]

#javascript #array #methods #arrowfunction

Dylan  Iqbal

Dylan Iqbal

1622607992

25 JavaScript Array Methods Every Developer Should Know

Master JavaScript arrays with these 25 methods and become a more productive JavaScript developer.

Arrays are wonderful and a very particular type in JavaScript. There are many useful built-in properties and methods that will help you resolve any task which involves arrays. Today we are going to discuss 25 array methods every developer should know.

  • every()
  • reduce()
  • flat()
  • filter()
  • findIndex()
  • find()
  • isArray()
  • from()
  • some()
  • indexOf() and lastIndexOf()
  • shift()
  • unshift()
  • pop()
  • push()
  • reverse()
  • join()
  • includes()
  • fill()
  • concat()
  • sort()
  • splice()
  • slice()
  • map()
  • forEach()

#javascript #array #web-development #programming #developer