I have a set of arrays in json as followed:
{"status":200,"success":true,"result":
[{"id":"0","NameInData":"","name":"","type":"mf","greeting":"Bonjour","message":"GENERIC: Lorem ipsum."},
{"id":"1","NameInData":"alexis","name":"Alexis","type":"mf","greeting":"Bonjour Alexis","message":"ONE: Lorem ipsum."},
{"id":"2","NameInData":"laurence","name":"Laurence","type":"ff","greeting":"Hello Laurence","message":"TWO: Lorem ipsum."},
{"id":"3","NameInData":"francois","name":"Francois","type":"mm","greeting":"Konnichiwa Francois","message":"THREE: Lorem ipsum."},
{"id":"4","NameInData":"dirk","name":"Dirk","type":"mf","greeting":"Ni hao Dirk","message":"FOUR: Lorem ipsum."},
{"id":"5","NameInData":"coline","name":"Coline","type":"ff","greeting":"high 5! Coline","message":"FIVE: Lorem ipsum."}]}
I am able to identify the value of a key from this array, and //do something with it with the following code:
$.each(json.result, function(){
if (this.name == content){
//do something
var identifiedID = this.id;
console.log("PRINT ID: " + identifiedID);
var name = json.result[identifiedID].name;
var $nameText = $("#nameText"),
str = name;
html = $.parseHTML(str),
nodeNames = [];
$nameText.append(html);
console.log("Name: " + name);
} else {
var identifiedID = 0;
console.log("PRINT ID: " + identifiedID);
var name = content;
var $nameText = $("#nameText"),
str = name;
html = $.parseHTML(str),
nodeNames = [];
$nameText.append(html);
console.log("Name: " + name);
});
I am trying to //do other things if the name is not unidentified within the list with the following code. However, as my array has 6 items, the output would be repeating the whole process 6 times, where I would only want one output, one result (either, a name and its id has been identified and print what it is related to OR a name has not been recognised and the id would be set to 0 and print what it is related.)
You may find my full code in the link here. It would be very nice if someone could tell me which part of my syntax is wrong please?
{"id": "3"...will be at index [3]? Because if that's not a certainty, I can see a gap in your logic.