I have a MySQL query that is executed by AngularJs Ajax.
It gives data from an array of objects. With console.log () it looks like this:
The table from which I get the data looks like this:
id meaning_ID word 1 1 a2 1b3 2c4 2d5 2 e6 3f< / Pre>So as you see, some words mean the same meaning as the other, and I want to collect these words in something.
I have thought of an array in which all words should be in the same sense_and an index, for example, the synonyms / objects should be A and B.
I have tried to:
$ scope.prepareSynonymsArray = function (for $ {scope.responseData in var key} {var obj = $ Scope.response data [key]; If (type $ scope.synonyms [obj.meaning] == "undefined") {$ scope.synonyms [obj.meaning] = obj; } And {$ scope.synonyms [obj.meaning] .push (obj); }} Console.log ($ scope.synonyms); }But there may be a mistake in the push function. Is there any better way to achieve this? Please give me some suggestions.
Kind regards, Force 0234
If intention is that $ Scope.synonyms [obj.meaning] should be an array (given that you try later on .push elements), then the undefined case It must be set to [obj] , not only obj :
if (typeof $ scope.synonyms [obj] .meaning] == "undefined") {$ scope.synonyms [obj.meaning] = [obj]; // initial array} with an element and {$ scope.synonyms [obj.meaning] .push (obj); // additional element}
No comments:
Post a Comment