admin管理员组文章数量:1418342
I want to dynamically build an array that will eventually look like this
var data2 = [
[gd(2013, 5, "23"), 33], [gd(2013, 5, 24), 41], [gd(2013, 5, 25), 29], [gd(2013, 5, 26), 12], [gd(2013, 5, 28), 17]
];
The rest of the code is very hacky from this point onwards as I want it to work before actually making it streamlined...
I build my string like it is above
varData = '[gd(' + thisYear + ',' + thisMonth + ',' + thisDay + '),' + thisInt + ']';
Then I push it to the array data2
data2.push(varData);
This created the array that outputs this -
["[gd(2013,23,5),4]", "[gd(2013,24,5),41]", "[gd(2013,28,5),4]"]
How would I get that same array without the "'s around each index? Or am I going about this in COMPLETELY the wrong way? I don't have too much experience with using arrays in this way, so I'm not sure if it could be built dynamically, or even where to begin.
Edit/Update: The missing gd function!!
function gd(year, month, day) {
return new Date(year, month - 1, day).getTime();
}
I want to dynamically build an array that will eventually look like this
var data2 = [
[gd(2013, 5, "23"), 33], [gd(2013, 5, 24), 41], [gd(2013, 5, 25), 29], [gd(2013, 5, 26), 12], [gd(2013, 5, 28), 17]
];
The rest of the code is very hacky from this point onwards as I want it to work before actually making it streamlined...
I build my string like it is above
varData = '[gd(' + thisYear + ',' + thisMonth + ',' + thisDay + '),' + thisInt + ']';
Then I push it to the array data2
data2.push(varData);
This created the array that outputs this -
["[gd(2013,23,5),4]", "[gd(2013,24,5),41]", "[gd(2013,28,5),4]"]
How would I get that same array without the "'s around each index? Or am I going about this in COMPLETELY the wrong way? I don't have too much experience with using arrays in this way, so I'm not sure if it could be built dynamically, or even where to begin.
Edit/Update: The missing gd function!!
function gd(year, month, day) {
return new Date(year, month - 1, day).getTime();
}
Share
Improve this question
edited May 28, 2013 at 14:29
Gary Kenyon
asked May 28, 2013 at 13:39
Gary KenyonGary Kenyon
3681 gold badge6 silver badges20 bronze badges
6
- what kind of expression is gd()? – Thomas Junk Commented May 28, 2013 at 13:41
-
7
You're almost certainly going about this the wrong way. What is
gd
? – Dark Falcon Commented May 28, 2013 at 13:41 -
gd(2013, 5, "23")
is not a valid value, it should be a string – Arun P Johny Commented May 28, 2013 at 13:46 -
So you want it to appear when outputted by the console to not show the
"
in there (which wouldn't make much sense) or do you actually want that to be an array? Also do you want thegd(...), thisInt
bit stored as a string or as 2 actual elements? – Qantas 94 Heavy Commented May 28, 2013 at 13:51 - 2 XY Problem? – user1106925 Commented May 28, 2013 at 13:52
2 Answers
Reset to default 4If you really want exactly what you have in the first example, then you would build that like this:
var data2 = [];
// For each item:
data2.push([gd(thisYear, thisMonth, thisDay), thisInt]);
Just push the array directly and not in form of a string:
data2.push( [ 'gd(' + thisYear + ',' + thisMonth + ',' + thisDay + ')', thisInt ] );
本文标签: javascriptPush to array without Quotesor remove quotes from arrayStack Overflow
版权声明:本文标题:javascript - Push to array without Quotes, or remove quotes from array - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745288702a2651660.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论