[英]javascript alert prints Object Object
this is my code which prints below output on the alert.这是我的代码,它在警报输出下方打印。
alert(JSON.stringify( args.errors,null,4));
this is the output.这是输出。
{
"Weight":{
"errors":[
"Hello My name is John"
]
}
}
I just want "Hello My name is john" in the alert box.我只想在警报框中显示“你好,我的名字是约翰”。 Any help will be great
任何帮助都会很棒
You can use args.Weight.errors.join(', ')
to alert the errors.您可以使用
args.Weight.errors.join(', ')
来提醒错误。
In case if there is only one error, it will be shown.如果只有一个错误,则会显示。 Otherwise, all the errors will be separated by
,
.否则,所有的错误都会被分开
,
。
I am assuming you are having我假设你有
let args = { "Weight":{ "errors":[ "Hello My name is John" ] } }; alert(args.Weight.errors.join(', '));
It should work.它应该工作。
I assume the output you mentioned is the error data and you want to display the errors from the that.我假设您提到的输出是错误数据,并且您希望显示错误数据。
const data = {
Weight: {
errors: ["Hello My name is John"]
}
};
To alert the users with above data you can use要使用上述数据提醒用户,您可以使用
alert(data.Weight.errors[0])
Test at snippet at CodeSandbox在CodeSandbox 的片段上进行测试
If args
is your object, you could simply alert args.Weight.errors
and, in case there is more than one error, add join(', ')
to list them separated by ,
.如果
args
是您的对象,您可以简单地提醒args.Weight.errors
并且,如果有多个错误,请添加join(', ')
以列出它们,以,
分隔。
let args = { "Weight": { "errors": [ "Hello My name is John" ] } }; alert(args.Weight.errors.join(', '));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.