Join the Stack Overflow Community
Stack Overflow is a community of 6.6 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

I need to get object in array for the given index in angular js.

scope.storeList = [{
  'id':101,
  'name':indhu
},{
  'id':102,
  'name':selvin
},{
  'id':103,
  'name':indhu1
}];

In this if i give index value, it should give the object. I tried this below code but could not get:

var list = scope.storeList[2];

Please some one help it.

share|improve this question
    
angular.js:13424 TypeError: Cannot read property '0' of undefined – Indhu Oct 26 '16 at 10:01
    
sure:) But what i have done is correct. it worked after sometimes. – Indhu Oct 27 '16 at 10:54
up vote 0 down vote accepted

name values should be in string type.

$scope.storeList = [{
  'id':101,
  'name':"indhu"
},{
  'id':102,
  'name':"selvin"
},{
  'id':103,
  'name':"indhu1"
}];
 console.log("",$scope.storeList[2])
share|improve this answer

There is a syntax error in your JSON object: string must be between quotes:

$scope.storeList = [{
  'id':101,
  'name':'indhu'
},{
  'id':102,
  'name':'selvin'
},{
  'id':103,
  'name':'indhu1'
}];

var list = $scope.storeList[2];
console.log(list); // prints Object { id: 103, name: "indhu1" }

Try it on JSFiddle here (don't forget to open console).

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.