gpt4 book ai didi

javascript - Immutable.JS 联系和修改输出

转载 作者:行者123 更新时间:2023-11-29 23:11:21 25 4
gpt4 key购买 nike

在 immutableJS 中,我试图将输出输出到 .

name: "此字段为必填项。另一个错误。", age: "只允许使用数字字符。"

 const Immutable = require("immutable");
let error = Immutable.fromJS({
name: ["This field is required", "Another error"],
age: ["Only numeric characters are allowed"]
});

最佳答案

ONELINER:就地(对 this version of question 的回答 - 示例)

Object.entries(error).map( x=> error[x[0]] = x[1].join('. ')+'.' );

let error = {
name: ["This field is required", "Another error"],
age: ["Only numeric characters are allowed"]
};


Object.entries(error).map(x=>error[x[0]]=x[1].join('. ')+'.');
console.log(error);

通过这种方式,您可以将其包装在函数中(不可变):

let var func = (e,r={})=>(Object.entries(e).map(x=>r[x[0]]=x[1].join('. ')+'.'),r);
let result = func(error) // run it in this way

关于javascript - Immutable.JS 联系和修改输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53820878/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com