JavaScript
JavaScript Array Methods
Array length
*The length property returns the length (size) of an array.
example:
var a = [ "welcome" ];
console.log(  a . length )
output : 1
var a =[ "welcome", "you"]
console.log( a. length)
output : 2
var a = [ "welcome", "you", "all"]
console.log(  a . length );
output : 3
var a = [" array to a string " ]
console.log(  a . length );
output : 3
Array toString()
what is Array toString() ?
- The JavaScript method toString() converts an array to a string of (comma separated) array values.
- The elements are then joined together into a single string, with each element separated by a comma.
example:
var array = ["welcome", "you", "all"]
console.log ( array.toString())
output: 
welcome,you,all
var a = [ "red ", "yellow","green"]
console.log( a .toString())
output :
 red,yellow, green
var b = [ "onedrive ","mouse", "desktop"]
console.log( b. toString());
output : 
onedrive ,mouse, desktop
JavaScript Array at()
- The at() method returns an indexed element from an array. The at() method returns the same as [] .
example:
var array = ["welcome", "you", "all"]
console.log ( array.at())
console.log(' ');
var a = [ "red ", "yellow","green"]
console.log( a .at(1))
console.log(' ');
var b = [ "onedrive ","mouse", "desktop"]
console.log( b. at(2));
console.log(' ');
var b = [ "onedrive ","mouse", "desktop"]
console.log( b. at(-1));
console.log(' '); ||| get last element in array at
JavaScrpit join()
- The join() method also joins all array elements into a string.
- It behaves just like toString(), but in addition you can specify the separator:
var array = ["welcome", "you", "all"]
console.log ( array.join('!'))
console.log ( array.join('@'))
console.log ( array.join('$'))
console.log ( array.join('^'))
console.log ( array.join('&'))
console.log ( array.join('*'))
console.log ( array.join(' '))
console.log ( array.join(' '))
console.log ( array.join(' '))
console.log ( array.join('+'))
output:
welcome!you!all
welcome@you@all
welcome$you$all
welcome^you^all
welcome&you&all
welcome*you*all
welcome you all
welcome you all
welcome you all
welcome+you+all
Comments
Post a Comment