We can declare an array by using its constructor or by breaking string using delimiter.
https://www.plus2net.com/javascript_t...
https://www.plus2net.com/javascript_t...
script = new Array();
We can add elements to this array like this .
script[0]='PHP'
script[1]='Python'
script[2]='JavaScript'
script[3]='JQuery'
Index position of first element is 0 , so here we have added 4 elements with last element at position 3.
We can display the array elements by using document.write()
document.write( script);
We can also create array by using split() method. We can specify the delimiter and break the string to create an array. If we don’t specify the delimiter then full string will be returned as single element array. If we specify the delimiter than same is used to break the string and create the array.
str=’welcome to plus2net’
a1=str.split(“”)
We can add one limit option to this split() method to restrict number of elements to be included in the created array.
a1=str.split(“”,2)
Here there will be two element in our array a1.
We can use split() to separate userid and domain part from one email address. Here we will use @ as delimiter.
#javascriptarray #javascriptcreatearray #javascriptsplitarray
On this page of the site you can watch the video online Creating arrays in JavaScript & adding elements by using constructor and breaking string using split with a duration of hours minute second in good quality, which was uploaded by the user plus2net 18 April 2021, share the link with friends and acquaintances, this video has already been watched 614 times on youtube and it was liked by 1 viewers. Enjoy your viewing!