jquery创建二维数组 [英] jquery creating two dimensional array

查看:214
本文介绍了jquery创建二维数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

看来我对我想要完成的事情有点困惑.感谢那些花时间解释这一点的人,谢谢.

It appears I was a bit confused on what I was trying to accomplish. For those that took the time to explain this, thank you.

我正在尝试在 Jquery/Javascript 中创建一个二维数组.我已经做了大量的搜索、测试和更多的搜索,但我无法找到对我来说真正有意义的解决方案.(这已经是很长的一周了....)

I'm trying to create a two dimensional array in Jquery/Javascript. I've done a decent amount of searching, testing and more searching but i'm unable to find a solution that really makes sense to me. (it's been a very long week already....)

以下是所需的数组格式.

Below is the desired format of the array.

{"product":[{"attribute":"value","attribute":"value"}]}

推荐答案

那不是二维数组,而是一个对象.此外,您的产品数组仅包含一个对象.我认为你需要这样的东西:

That's not a 2D array, but rather an object. Also, your product array contains only one object. I think you need something like this:

var obj = {};
obj.product = [];
for(var i=0; i < someObj.length; i++) {
   obj.product.push[{"attribute": someObj[i]}]
}

这将在 product 属性中生成一个数组:

This will produce an array inside the product property:

{"product":[{"attribute":"value"}, {"attribute":"value"}]}

这篇关于jquery创建二维数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆