Arrays

Dear Sciaku Learner you are not logged in or not enrolled in this course.

Please Click on login or enroll now button.

If you have any query feel free to chat us!

Happy Coding! Happy Learning!

Lecture 142:- Arrays

Arrays in JavaScript are a type of data structure used to store a collection of elements of the same data type or different data types. An array can store a list of strings, numbers, objects, or any other data type.

In JavaScript, arrays are created using square brackets [] with comma-separated values inside the brackets. For example:

arduinoCopy code

const numbers = [1, 2, 3, 4, 5]; const fruits = ['apple', 'banana', 'orange']; const mixed = [1, 'apple', true, { name: 'John' }];

Arrays in JavaScript are zero-indexed, which means the first element is at index 0, the second element is at index 1, and so on. You can access elements in an array using their index. For example:

arduinoCopy code

const numbers = [1, 2, 3, 4, 5]; console.log(numbers[0]); // Output: 1 console.log(numbers[2]); // Output: 3

Arrays in JavaScript have various built-in methods that can be used to manipulate them. Some of the commonly used array methods include:

  • push(): adds one or more elements to the end of an array.
  • pop(): removes the last element from an array.
  • shift(): removes the first element from an array.
  • unshift(): adds one or more elements to the beginning of an array.
  • splice(): adds or removes elements from an array at a specified index.
  • concat(): merges two or more arrays into one new array.
  • slice(): returns a portion of an array.
  • sort(): sorts the elements in an array.
  • reverse(): reverses the order of elements in an array.

There are many other array methods available in JavaScript, each with its own use case.

16. JavaScript - Functions and Array

2 Comments

@niteshguptav63
niteshguptav63 Nov 17, 2024 at 1:39 PM

I am not able to access videos from second class and further. I have already completed first class

@niteshguptav63
niteshguptav63 Nov 16, 2024 at 10:56 AM

When will I get my course?

@admin79
admin79 Nov 17, 2024 at 1:29 PM

Now, Your query was resolved.

Frequently Asked Questions About Sciaku Courses & Services

Quick answers to common questions about our courses, quizzes, and learning platform

Didn't find what you're looking for?

help_center Contact Support