Arrays in JavaScript - JavaScript Tutorial 96

Publicado em: 22 Fevereiro 2022
no canal de: 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


Nesta página do site você pode assistir ao vídeo on-line Arrays in JavaScript - JavaScript Tutorial 96 duração hora minuto segundo em boa qualidade , que foi baixado pelo usuário ChidresTechTutorials 22 Fevereiro 2022, compartilhe o link com seus amigos e conhecidos, no youtube este vídeo já foi visto 1,017 vezes e gostou 34 espectadores. Boa visualização!