Arrays in JavaScript - JavaScript Tutorial 96

Publié le: 22 février 2022
sur la chaîne: ChidresTechTutorials
1,017
34

Notes for You:: Arrays in JavaScript - JavaScript Tutorial 96

Array:
Array is a collection of data elements (or data values).
Arrays are created to store multiple values in a single variable.

Note:
Each element in the array is going to have an index; hence arrays are also called as indexed variables.
Arrays follow 0 based indexing; i.e. first element in the array is going to have an index 0.


How to declare and initialize a variable of type array:

Syntax 1: using constructor notation
var arrayName = new Array(comma separated list of values);
Ex:
var studNames = new Array(“Ram”,”Ravi”,”Raju”,”Raghu”,”Gopal”);

Syntax 2: using literal notation
var arrayName = [comma separated list of values];
Ex:
var studNames = [“Ram”,”Ravi”,”Raju”,”Raghu”,”Gopal”];



How to get value of an array element:
We can get value of an array element by its index.

Syntax:
arrayName[index]

Ex:
document.write( studNames[0] ); // Ram


How to set new value to an array element:
We can set new value to an array element using assignment operator.

Syntax:
arrayname[index] = newvalue;

Ex:
studNames[0]=”Rahul”;
document.write(studNames[0]); // Rahul



Example Code:
// var studNames = new Array("Ram","Ravi","Raju","Raghu","Gopal");

var studNames = ["Ram","Ravi","Raju","Raghu","Gopal"];

document.write( studNames[0] ); // Ram
document.write( studNames[1] ); // Ravi
document.write( studNames[2] ); // Raju
document.write( studNames[3] ); // Raghu
document.write( studNames[4] ); // Gopal

studNames[0] = "Rahul";

document.write( studNames[0] ); // Rahul
document.write( studNames[1] ); // Ravi
document.write( studNames[2] ); // Raju
document.write( studNames[3] ); // Raghu
document.write( studNames[4] ); // Gopal

=========================================

Follow the link for next video:
JavaScript Tutorial 97 - Traversing an Array in JavaScript | JavaScript Array Traversal
   • Traversing Arrays in JavaScript - Jav...  

Follow the link for previous video:
JavaScript Tutorial 95 - Email ID Validation in JavaScript with Regular Expression
   • JavaScript Email Validation: RegExp -...  

=========================================

JavaScript Tutorials Playlist:-
   • JavaScript Tutorials  

=========================================
Watch My Other Useful Tutorials:-

jQuery Tutorials Playlist:-
   • jQuery Tutorials  

jQuery UI Tutorials Playlist:-
   • jQuery UI Tutorials  

Bootstrap Tutorials Playlist:-
   • Bootstrap4 Tutorials  

=========================================

► Subscribe to our YouTube channel:
   / chidrestechtutorials  

► Visit our Website:
https://www.chidrestechtutorials.com

=========================================
Hash Tags:-
#ChidresTechTutorials #JavaScript #JavaScriptTutorial


Sur cette page du site, vous pouvez voir la vidéo en ligne Arrays in JavaScript - JavaScript Tutorial 96 durée heure minute seconde en bonne qualité , qui a été Téléchargé par l'utilisateur ChidresTechTutorials 22 février 2022, Partagez le lien avec vos amis et connaissances, sur youtube cette vidéo a déjà été regardée 1,017 fois et il a aimé 34 téléspectateurs. Bon visionnage!