Arrays in JavaScript - JavaScript Tutorial 96

Publicado el: 22 febrero 2022
en el 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


En esta página del sitio puede ver el video en línea Arrays in JavaScript - JavaScript Tutorial 96 de Duración hora minuto segunda en buena calidad , que subió el usuario ChidresTechTutorials 22 febrero 2022, comparta el enlace con amigos y conocidos, en youtube este video ya ha sido visto 1,017 veces y le gustó 34 a los espectadores. Disfruta viendo!