I have an object in localstorage and would like to match the last element that I have added when I called $(‘form’).serializeArray();
I am trying to match the text from a dropdown that is populated with the keys from localStorage. I have managed this. I then check to see if I have a match with the text and get the localStorage item. I return this and parse the result I get back all my items in local storage but I would like the last name and value in the matching object.
I’m not really sure what Im doing but strugging how to achieve the name and value. It just gives me all of them.
var matchDdlValue = function () {
var result = [],
ddlValue = $('#ddl option:selected').text();
for (var i = 0; i < keyMatch.length; i++) {
if (keyMatch.indexOf(ddlValue) != -1) {
}
}
result.push(ddlValue);
var l = localStorage.getItem(result);
var jsn = JSON.parse(l);
for (var j = 0; j < jsn.length; j++) {
var obj = jsn[i];
console.log(obj.name + ": " + obj.value);
}
console.log(result);
return result;
}