Suppose I have the following array- var x= ["hello"];
Can i further break it into a character array like this one- var x_character= ["h","e","l","l","o"];
if not, can you tell me how to know the character length of the x array..
Suppose I have the following array- var x= ["hello"];
Can i further break it into a character array like this one- var x_character= ["h","e","l","l","o"];
if not, can you tell me how to know the character length of the x array..
Yes, use the .split() method:
var x = ["hello"]
x[0].split("")
Returns the array ["h","e","l","l","o"]
. The ""
argument means to split the string at each empty substring.
Create a new empty array, iterate through the original array and push each character into the new array. To get the length of the original array - use "x.length" (ie: "var arrayLength=x.length";)
var x = ["hello"];
var x_character=[];
for(i=0;i<x.length;i++)
{
var x_character.push(x[i])
}