Can someone please explain in simple terms what this does? I looked up but didnt really understand.
First thing is the console.log. I often see this. What does it mean? Then the id.split part is confusing too.
console.log(id);
id = id.split(" ");
Can someone please explain in simple terms what this does? I looked up but didnt really understand.
First thing is the console.log. I often see this. What does it mean? Then the id.split part is confusing too.
console.log(id);
id = id.split(" ");
console.log writes the value to the JavaScript Console.
id.split(" ")
splits the string id
at the space into an array.
var id = "This is a string";
var idParts = id.split(" ");
for(var i = 0; i < idParts.length; i++) {
console.log(idParts[i]);
}
The above will output "This", "is", "a", and "string" to the javascript console.
Console.log
will print the id to the console. And split
function will split the string into multiple arrays.
For example if id = "I love stackoverflow";
If you use
id.split(" ")
will result in an array with 3 components: "I", "love" and "stackoverflow".