Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

从数组对象中取得某对象的index #2

Open
jinjiaxing opened this issue Nov 30, 2017 · 0 comments
Open

从数组对象中取得某对象的index #2

jinjiaxing opened this issue Nov 30, 2017 · 0 comments

Comments

@jinjiaxing
Copy link
Owner

jinjiaxing commented Nov 30, 2017

 /**
     * 判断某对象在数组中的inde
     * @param obj
     * @param list
     */
    function getObjectInArrayIndex = (obj, list) => {
        if (!list || !(list instanceof Array)) {
            return -1;
        }
        if (!obj) {
            return -1;
        }
        return list.indexOf(list.filter(item => {
            return JSON.stringify(item) === JSON.stringify(obj)
        })[0])

目前想到的比较简单的写法,大家可以讨论下性能,或者提供下更好的写法

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant