![]() See carefully what they need in the output result ,they want the result to be like this :įrankenSplice(,, 1) should return, in other words they want from you to use slice and splice, slice for copying arr2 because they want arr2 to be unchanged, and then you can use splice to add elements from copying array that you got from slice method and as it known the splice method has three parameters, array.splice(index, howmany, item1, …, itemX) here index=n and n is from where you can start adding ,howmany should stay 0,and item1=the element you wanna add to the copied array. Understanding the Problem: We have one input, a string.Our output is also a string. ![]() The splice() method changes the original array and slice() method doesn’t change the original array. You can also fork this sandbox and keep building it using our online code editor for React, JavaScript, Node.js, and other web programming languages. this tutorial shows you how to use the JavaScript Array splice method to delete existing elements, insert new elements, and replace elements in an array. The splice() method returns the removed item(s) in an array and slice() method returns the selected element(s) in an array, as a new array object. ![]() In your code( the const end) is just concatenating the two element 5 and 6 from arr2 to arr1 ,and concat method is not suitable here Splice and Slice both are Javascript Array functions. JavaScript built-in methods help us a lot while programming, once we understand them correctly.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |