/
spirzen
/
it-code-examples
Обзор
Документация
Войти
/
spirzen
/
it-code-examples
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
examples/javascript/js-501-22-048/main.js
26 строк
830 B
Spirzen
Code migration pack
09 июн 2026, 01:41
09 июн 2026, 01:41
cebc284
Код
Авторство
О чём код?
const product = { name: "Ноутбук", price: 50000, costPrice: 30000, // Себестоимость (не показываем) discount: 0.1, inStock: true }; // Исключение полей из сериализации const jsonString = JSON.stringify(product, ["name", "price", "discount", "inStock"]); console.log(jsonString); // '{"name":"Ноутбук","price":50000,"discount":0.1,"inStock":true}' // Преобразование значений const formatted = JSON.stringify(product, (key, value) => { if (key === "price") { return value + " ₽"; } if (key === "discount") { return (value * 100) + "%"; } return value; }); console.log(formatted); // '{"name":"Ноутбук","price":"50000 ₽","costPrice":30000,"discount":"10%","inStock":true}'