简体   繁体   中英

Whats wrong with this javascript syntax?

Below code not working in IE. Console shows syntax error. Whats wrong with this?

var text = '{"products":[' +
'{"name":"IB-400","mail":"9000@mail.pl"},' +
'{"name":"IB-500","mail":"8000@mail.pl"}]}';
var textObj = JSON.parse(text)
var mail = textObj.products.find(itm => itm.name == c).mail
$( ".komunikat" ).replaceWith( '<div class="komunikat-mail"><h1 style="text-align:center;">Contact</h1><p class="komunikat-paragraph">Lorem ipsum  ' + mail +'. Lorem ipsum.</p></div>' );

They syntax error is because you're using an arrow function in a browser that doesn't support them.

Change itm => itm.name == c to function ( itm ) { return itm.name == c } .

or use Babel to transpile ES6 to ES5 for you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM