-2

I have an array which looks like:

var standardsList = [
{"Grade": "Math K", "Domain": "Counting & Cardinality", "$$hashKey": "08932"},
{"Grade": "Math K", "Domain": "Counting & Cardinality", "$$hashKey": "07932"},
{"Grade": "Math K", "Domain": "Counting & Cardinality", "$$hashKey": "08332"},
{"Grade": "Math K", "Domain": "Counting & Cardinality", "$$hashKey": "08132"},
{"Grade": "Math K", "Domain": "Geometry", "$$hashKey": "08902"} ];

This $$hashKey attribute is added by angularJS by default

I want to remove this $$hashkey attribute with value from all objects of above array.

Any pointers anyone ??

Jad Chahine
  • 6,849
  • 8
  • 37
  • 59
NiranjanK
  • 427
  • 2
  • 6
  • 23
  • 1
    maybe you could refer to this thread: http://stackoverflow.com/questions/18826320/what-is-the-hashkey-added-to-my-json-stringify-result – ShivangiBilora Oct 23 '15 at 06:05
  • @Nirvana did my answer solve this issue for you? Please mark it correct or place your own answer. Thanks, – Enkode Oct 26 '15 at 03:05

3 Answers3

2

Repeat question / answer: What is the $$hashKey added to my JSON.stringify result

Angular adds this to keep track of your changes, so it knows when it needs to update the DOM.

If you use angular.toJson(obj) instead of JSON.stringify(obj) then Angular will strip out these internal-use values for you.

Also, if you change your repeat expression to use the track by {uniqueProperty} suffix, Angular won't have to add $$hashKey at all.

Otherwise this code will work to delete it:

var standardsList = [
{"Grade": "Math K", "Domain": "Counting & Cardinality", "$$hashKey": "08932"},
{"Grade": "Math K", "Domain": "Counting & Cardinality", "$$hashKey": "07932"},
{"Grade": "Math K", "Domain": "Counting & Cardinality", "$$hashKey": "08332"},
{"Grade": "Math K", "Domain": "Counting & Cardinality", "$$hashKey": "08132"},
{"Grade": "Math K", "Domain": "Geometry", "$$hashKey": "08902"} ];

for (var i=0; i<standardsList.length; i++){
  delete standardsList[i].$$hashKey;
}

console.log(JSON.stringify(standardsList));
Community
  • 1
  • 1
Enkode
  • 4,515
  • 4
  • 35
  • 50
0

Use map function to do this:

var newList = standardsList.map(function(obj){
   delete obj['$$hashKey'];

   return obj;
});
Niezborala
  • 1,857
  • 1
  • 18
  • 27
-1

One solution is to use a for each loop:

for each (element in standardsList)
{
    delete element.$$hashKey;
}
aditya_medhe
  • 362
  • 1
  • 19