Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

Sorry, you do not have permission to ask a question, You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please type your username.

Please type your E-Mail.

Please choose an appropriate title for the post.

Please choose the appropriate section so your post can be easily searched.

Please choose suitable Keywords Ex: post, video.

Browse

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Logo Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Logo

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Navigation

  • Home
  • About Us
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • About Us
  • Contact Us
Home/ Questions/Q 6678

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Latest Questions

Author
  • 60k
Author
Asked: November 27, 20242024-11-27T08:45:08+00:00 2024-11-27T08:45:08+00:00

Day 9 of 30 of JavaScript

  • 60k

Hey reader! Hope you are doing well:)
In the last post we have read about functions and how they are used in JavaScript. Taking our tutorial furthur we are going to study about arrays and different methods used for manipulating arrays.So let's get started…

What are Arrays?

An array is list of similar type entities.
For example we can store a list of 10 numbers in a data structure called array.

Declaration -:
Image description
In the above image you can see that I have used four general methods of declaring an array.
In the first method I have simply declared an array variable and then assigned the list of numbers to it.
In the second method I have made array using Array constructor (those who are not familiar with this term, don't worry we are going to study about it in upcoming blogs). In this I have passed the array entities inside constructor.
In the third method I have created an empty array and then assigned value to each index seperately.
(Note-: We retrieve elements of array using index {arr[0],arr[1],arr[2].....}. Index in array starts from 0 and goes till size of array-1.)
In the fourth method I have made an array using constructor but this time instead of giving entities, I have passed size of array and later in for loop I have assigned value to each index.
We can other methods too for declaring arrays.

Accessing Array Elements-:
You access an array element by referring to the index number.
Image description
So here you can see that we accessing array elements using index.
(Mango is at index 0.
Orange is at index 1.
Kiwi is at index 2.)

Note-:
Image description
While defining arrays above I have stated that arrays are list of similar type of entities. But above image is clear conflict to this statement. How this above declartion is even possible?
The above declaration is possible because in JavaScript, arrays are not restricted to storing elements of the same type. Unlike some strongly-typed languages, JavaScript arrays can hold elements of any data type, and these elements can be mixed within the same array. This flexibility is part of the dynamic nature of JavaScript.

Adding Array Element-:
The easiest way to add a new element to an array is using the push() method.
Image description
Now here the element is added to the end of the array.But what if we have to add element at some position other than end.We will use following method to achieve this:
Image description
Here we have used splice() method to add two elements after index 0.
array.splice(index, 0, element);
index is the position where the new element should be added.
The second parameter is the number of elements to remove (0 in this case, as we are only adding).
element is the new element to be added.
The splice() method adds new items to an array.

We can also use spread operator(…) to add elements to array-:
Image description
The spread operator is used here to expand the elements of the arr array into a new array newArr. This allows newArr to include 0 at the beginning, the elements of arr in the middle, and 4 at the end. The result is a combined array [0, 1, 2, 3, 4].

Length of array-:
The length property of an array returns the length of an array (the number of array elements).
Image description

So this is it for this blog. I hope you have understood it well. We will continue studying array in the next blog. Till then stay connected and don't forget to follow me 🙂

beginnersjavascripttutorialwebdev
  • 0 0 Answers
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

Sidebar

Ask A Question

Stats

  • Questions 4k
  • Answers 0
  • Best Answers 0
  • Users 2k
  • Popular
  • Answers
  • Author

    ES6 - A beginners guide - Template Literals

    • 0 Answers
  • Author

    Understanding Higher Order Functions in JavaScript.

    • 0 Answers
  • Author

    Build a custom video chat app with Daily and Vue.js

    • 0 Answers

Top Members

Samantha Carter

Samantha Carter

  • 0 Questions
  • 20 Points
Begginer
Ella Lewis

Ella Lewis

  • 0 Questions
  • 20 Points
Begginer
Isaac Anderson

Isaac Anderson

  • 0 Questions
  • 20 Points
Begginer

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help

Footer

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise

Querify Question Shop: Explore, ask, and connect. Join our vibrant Q&A community today!

About Us

  • About Us
  • Contact Us
  • All Users

Legal Stuff

  • Terms of Use
  • Privacy Policy
  • Cookie Policy

Help

  • Knowledge Base
  • Support

Follow

© 2022 Querify Question. All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.