I'm sure this is really simple but I am learning Javascript and I can't figure this out.
var niceDay = "please, have a nice day";
- How do I create an array using "niceDay", and output the array?
- how do I output the item in index 2?!
You can use the 'split' javascript function. This will split a string on a certain character and return an array:
var array = niceDay.split(' ');
This will return an array split on each space in the string. You can then access the second item in the array using:
var item = array[1];
Or assign the second item a new value using:
array[1] = 'string';