javascript - 如何从 javascript 函数返回两个参数?

标签 javascript

我有以下内容:

function getPk(entity) {
    var store = window.localStorage;
    switch (entity) {
        case "City":
            if (store.getItem('AccountID')) {
                // Need to return both of the below pieces of information
                return store.getItem('AccountID') + "04" + "000";
                return "CityTable";

            } else {
                paramOnFailure("Please reselect"); 
                return false;
            }
            break;

问题是我需要能够调用这个函数并返回两个字符串。在这里,我展示了两个返回语句,但我知道我不能那样做。

有没有一种干净的方法可以将两个字符串返回给调用我的 getPk(entity) 函数的函数?

如果可能的话,您能否也举例说明我如何读取返回的内容。

最佳答案

将它们作为数组或对象返回。

return [store.getItem('AccountID') + "04" + "000", "CityTable"];

return { accountID: store.getItem('AccountID') + "04" + "000", table: "CityTable" };

关于javascript - 如何从 javascript 函数返回两个参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10561037/

相关文章:

javascript - jquery + ajax。我的 javascript 函数出了什么问题?删除记录、添加记录而不刷新

javascript - 如何使用 Vue JS 从下拉列表中删除数组中的项目

javascript - 在vue按钮事件中传递对象值

javascript - jsdoc 别名方法名

c# - 无法在 Razor View 中设置 javascript 对象

javascript - 将参数作为字符串传递包含javascript onclick函数中的空格

javascript - 如何在Canvas中绘制半径对称的六条线?

javascript - 使用 gulp-useref 和 gulp-less 编译 LESS?

javascript - Vue 3 : Receiving "r.default is not a constructor" error while using Vue Material

javascript - 如何切换阅读更多功能的可见性版本?