Javascript methods

what is the difference between split and slice method in javascript?

const secretMessage = animals.map(names => {
    return names[0].slice();
const secretMessage = animals.map(names => {
    return names[0].split();
})
``` I log them both in the console and yield same result .

Let’s clear up the confusion around the slice( ), splice( ), & split( ) methods in JavaScript this is a good article.

The main confusion you seem to have is that you need to pass parameters into both of the methods. slice takes a to and from index of where it is slicing, and split takes a separator parameter on what to split around.

1 Like

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.