Pergunta de entrevista da empresa Dassault Systèmes

Q. Difference between slice and splice function.

Resposta da entrevista

Sigiloso

22 de jul. de 2019

splice() changes the original array whereas slice() doesn't but both of them returns array object. var array=[1,2,3,4,5]; console.log(array.splice(2)); This will return [3,4,5]. The original array is affected resulting in array being [1,2]. var array=[1,2,3,4,5] console.log(array.slice(2)); This will return [3,4,5]. The original array is NOT affected with resulting in array being [1,2,3,4,5].

2