使用javascript连接两个数组

concatenate two arrays using javascripts

本文关键字:两个 数组 javascript 连接 使用      更新时间:2023-09-26

我在该页面上有一个页面分页,在选择一个或多个图像后会出现最初可选择的图像。用户将点击更多活动,他想从该页面中选择更多图像,然后点击确认按钮,所有选定的图像都将进入一个阵列,请帮助我。

检查这个屏幕

现在就像这个即将到来的

localhost/carc_app1/user/modal.php?ids=[{"id":"瑜伽"},{"id":"有氧运动"}]

但我想连接两个阵列

localhost/carc_app1/user/modal.php?ids=[{"id":"瑜伽"},{"id":"有氧运动"}

var item = JSON.parse(localStorage.getItem("test"));
//current page value
 var item_json = JSON.stringify(item) ;

 var page= <?php echo $json_value; ?>;
 var set_image=JSON.stringify(page) ;
 var image=set_image.concat(item_json);
 alert(image);
// Ok. Let's just parse it once instead of turning it
// into a string and reparsing it 57 times needlessly.
var item = JSON.parse(localStorage.getItem("test"));
// No!!! What is your obsession with stringify???
//current page value
//var item_json = JSON.stringify() ;
 var page= <?php echo $json_value; ?>;
// NO. just no.
//var set_image=JSON.stringify(page) ;
 var image=page.concat(item);
// You can't alert an array, try console instead
//alert(image);
console.log(image);