Arrays in JavaScript - JavaScript Tutorial 96

Veröffentlicht am: 22 Februar 2022
auf dem Kanal: 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


Auf dieser Seite können Sie das Online-Video Arrays in JavaScript - JavaScript Tutorial 96 mit der Dauer stunde minuten sekunde in guter Qualität ansehen, das der Benutzer ChidresTechTutorials 22 Februar 2022 hochgeladen hat, den Link mit Freunden und Bekannten teilen, dieses Video wurde auf Youtube bereits 1,017 Mal angesehen und es wurde von 34 den Zuschauern gefallen. Viel Spaß beim Betrachtenden Zuschauern gefallen!