1.0 KiB
1.0 KiB
title | localeTitle |
---|---|
Add Elements to the End of an Array Using concat Instead of push | إضافة عناصر إلى نهاية صفيف باستخدام concat بدلاً من الضغط |
إضافة عناصر إلى نهاية صفيف باستخدام concat بدلاً من الضغط
عندما تضيف طريقة push
عنصرًا جديدًا إلى نهاية الصفيف الأصلي ، تنشئ طريقة concat
صفيفًا جديدًا يحتوي على العناصر من الصفيف الأصلي والعنصر الجديد. الصفيف الأصلي لا يزال هو نفسه عند استخدام concat
.
روابط ذات صلة:
حل
`function nonMutatingPush(original, newItem) {
// Add your code below this line
return original.concat(newItem);
// Add your code above this line }
var first = [1, 2, 3]; var second = [4, 5]; nonMutatingPush(first, second); `