在JavaScript array_flip? [英] array_flip in javascript?

查看:159
本文介绍了在JavaScript array_flip?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有什么快捷方式办成 PHP的array_flip 在JavaScript或不它必须通过暴力循环呢?

Is there any shortcut to accomplishing the equivalent of PHP's array_flip in javascript or does it have to be done via brute force looping?

它被用于几十阵列因此,即使小的加速可能会增加。

It has to be used for dozens of arrays so even small speedups will probably add up.

推荐答案

不要以为有一内置例实施这里,虽然。)

Don't think there's one built in. Example implementation here, though :).

function array_flip( trans )
{
    var key, tmp_ar = {};

    for ( key in trans )
    {
        if ( trans.hasOwnProperty( key ) )
        {
            tmp_ar[trans[key]] = key;
        }
    }

    return tmp_ar;
}

这篇关于在JavaScript array_flip?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆