1

I'm passing an Object from an array of objects to a function. Is it possible to still retrieve the index number somehow from the object in the function? I'm doing this in javaScript specifically within the controller of AngularJS.

For instance

var array= [
    {
        name: "name1"
    },
    {
        name: "name2"
    }
];

function( passedInObjectFromArray ) {
    return passedInObjectFromArray.indexVal;
}

1 Answer 1

1

Yes you can do,

$scope.retrieveIndex =  function(passedInObjectFromArray){
    return array.indexOf(passedInObjectFromArray);
 }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.