Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
87
rated 0 times [  88] [ 1]  / answers: 1 / hits: 18870  / 7 Years ago, sun, september 10, 2017, 12:00:00

In JavaScript script I have created following dictionary.



var dictionary =[];
$(function () {
dictionary.push({
key: @item.Key.ToShortDateString().ToString(),
value: @Html.Raw(JsonConvert.SerializeObject(item.Value)),
});
alert(dictionary['2017-09-19']);
});


In alert it shows me undefined. How can I read value from this dictionary?


More From » jquery

 Answers
2

Rather than using an array use an object



$(function () {
var dictionary = {};
dictionary[@item.Key.ToShortDateString().ToString()] = @Html.Raw(JsonConvert.SerializeObject(item.Value));
alert(dictionary['2017-09-19']);
});

[#56526] Thursday, September 7, 2017, 7 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
tye

Total Points: 415
Total Questions: 103
Total Answers: 116

Location: Iraq
Member since Fri, Jun 5, 2020
4 Years ago
;