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
On this page of the site you can watch the video online Arrays in JavaScript - JavaScript Tutorial 96 with a duration of hours minute second in good quality, which was uploaded by the user ChidresTechTutorials 22 February 2022, share the link with friends and acquaintances, this video has already been watched 1,017 times on youtube and it was liked by 34 viewers. Enjoy your viewing!