将键和值都打印到控制台

时间:2018-02-05 04:35:27

标签: javascript vue.js

我正在尝试在表单上呈现一致的错误消息,但我的错误如下:

OBJECT:

{ "email": [ "can't be blank" ], "password": [ "can't be blank" ] }

预期信息

email can't be blank
password can't be blank

那么,如何将该对象转换为“预期消息”?

1 个答案:

答案 0 :(得分:2)

您可以使用for循环来实现此目的。连接密钥和消息。

var json = { "email": [ "can't be blank" ], "password": [ "can't be blank" ] }

for ( var key in json ) {
    console.log( key + " " + json[key] );
}