Creating arrays in JavaScript & adding elements by using constructor and breaking string using split

Pubblicato il: 18 aprile 2021
sul canale di: plus2net
614
1

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


In questa pagina del sito puoi guardare il video online Creating arrays in JavaScript & adding elements by using constructor and breaking string using split della durata di ore minuti seconda in buona qualità , che l'utente ha caricato plus2net 18 aprile 2021, condividi il link con amici e conoscenti, su youtube questo video è già stato visto 614 volte e gli è piaciuto 1 spettatori. Buona visione!