0

I am having this data

    var initialData = [
        { name: "Sweets", details: 352 },
        { name: "Spicy", details: "89 juwu jdbjd jd bdjh djh sdjh sjh sdhj sjh sjh shjdsjhsdhjsdhjshjdyrrrrrrrrrrrrrrrrrrr" },
        { name: "Salty", details: 23 }

];

Have to find the maximum length of 'details' field and get the output as 70(suppose length of details for name:'spicy') i.e maximum value .Need Solutions/Suggestions . Thanxs in advance .

user1260967
  • 89
  • 1
  • 2
  • 14

1 Answers1

0

finally i found the way out , answering as it may help somebody in future................ first take the count of your array

var count = 0; for (var p in initialData) { if (initialData.hasOwnProperty(p)) { count++; } } 

Fetch initialdata particular element and use loop to get max value

   var wid = 0; for (i = 0; i <= count-1; i++) { var temp1 = initialData[i].details.length; wid = wid > temp1 ? wid : temp1; }
user1260967
  • 89
  • 1
  • 2
  • 14