split a message js 1

split a message js

const message = 'This is a test'

var args = message.split(' ');

console.log(args[0]) // Responds "This"
console.log(args[1]) // Responds "is"
console.log(args[2]) // Responds "a"
console.log(args[3]) // Responds "test"

Here is what the above code is Doing:
1. We create a variable called message and assign it the value of a string.
2. We create a variable called args and assign it the value of the message variable split by spaces.
3. We log the first element of the args array to the console.
4. We log the second element of the args array to the console.
5. We log the third element of the args array to the console.
6. We log the fourth element of the args array to the console.

Similar Posts