简体   繁体   中英

Retrieve Index When Passing Object to Function

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;
}

Yes you can do,

$scope.retrieveIndex =  function(passedInObjectFromArray){
    return array.indexOf(passedInObjectFromArray);
 }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM