react-live icon indicating copy to clipboard operation
react-live copied to clipboard

spread syntax is not supported to split a string

Open mjarraya opened this issue 4 years ago • 1 comments

When attempting to split a string using the ... spread syntax, the behaviour is not consistent with JS specification:

const slicedPizza = [...'pizza'];

console.log(slicedPizza);
// expected ['p', 'i', 'z', 'z', 'a']
// actual ['pizza']

what bugs me is that the following examples behave as expected:

function sum(x, y, z) {
  return x + y + z;
}

const numbers = [1, 2, 3];

console.log(sum(...numbers));
// 6

let parts = ['shoulders', 'knees'];
let lyrics = ['head', ...parts, 'and', 'toes'];

console.log(lyrics)
// ['head', 'shoulders', 'knees', 'and', 'toes']

Can be reproduced by copying these examples in the playground

mjarraya avatar Sep 23 '21 08:09 mjarraya

hey @mjarraya -- i haven't been able to recreate this. it may have been addressed in changes since you opened this. please can you verify that it is still an issue?

jpdriver avatar Jan 26 '22 17:01 jpdriver