-5

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(" "); 
Steve
  • 111
  • 8
  • You print the id to the console, and then convert the string to an array by splitting it whereever there's a space. – arao6 Nov 09 '14 at 15:32
  • 1
    2 seconds on Google: [`console.log()`](https://developer.mozilla.org/en-US/docs/Web/API/Console.log) and [`String.prototype.split()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split) – h2ooooooo Nov 09 '14 at 15:33
  • https://developer.mozilla.org/en-US/docs/Web/API/Console.log http://www.w3schools.com/js/js_output.asp And, on stackoverflow... http://stackoverflow.com/questions/4539253/what-is-console-log – Brandon Nov 09 '14 at 15:33

2 Answers2

-1

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.

Robbert
  • 6,481
  • 5
  • 35
  • 61
-2

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".

Florin Pop
  • 5,105
  • 3
  • 25
  • 58
  • Florin Pop. Thank you for your great explanation. I really did do a google search but there were so many terminologies I didnt understand. – Steve Nov 09 '14 at 16:24