BROGRAMMIST Telegram 17
`JSON.stringify` metodida shu xususiyat borligini bilasizmi?

Obyektlarni `String`ga o'girib beruvchi bu metodni ko'pincha 1 ta parametr bilan ishlatamiz:
JSON.stringify(object)

Lekin metodda yana 2 ta (optional) parametr bor. To'liq korinishi:

JSON.stringify(
object,
?replacer,
?space
)

1. replacer - bu parametr funksiya yoki string'lar massivi bo'lishi mumkin.

Agar massiv bersak, obyektning faqat massivdagi elementlarga mos keluvchi field/maydonlarigina olinadi. Masalan:


> JSON.stringify({ a: 5, b: 3 }, ['b'])
> '{"b":3}'



Agar funksiya bo'lsa, u orqali biz field'larni filter qilishimiz mumkin:


> JSON.stringify(
{ a: 5, b: 3 },
(key, value) =>
key == 'a'
? 10
: value
)
> '{"a":10,"b":3}'




2. space - bu parametr orqali obyektimizni indentatsiya qilishimiz mumkin. Masalan space parametri 2 ga teng bo'lsa, natija quydagicha bo'ladi:


> var obj = { name: "Tony", status: { rank : 1, type: "Avenger"}}

> console.log(JSON.stringify(
obj,
undefined,
2
))

{
"name": "Tony",
"status": {
"rank": 1,
"type": "Avenger"
}
}

#js #tips #jsdaily



tgoop.com/brogrammist/17
Create:
Last Update:

`JSON.stringify` metodida shu xususiyat borligini bilasizmi?

Obyektlarni `String`ga o'girib beruvchi bu metodni ko'pincha 1 ta parametr bilan ishlatamiz:
JSON.stringify(object)

Lekin metodda yana 2 ta (optional) parametr bor. To'liq korinishi:

JSON.stringify(
object,
?replacer,
?space
)

1. replacer - bu parametr funksiya yoki string'lar massivi bo'lishi mumkin.

Agar massiv bersak, obyektning faqat massivdagi elementlarga mos keluvchi field/maydonlarigina olinadi. Masalan:


> JSON.stringify({ a: 5, b: 3 }, ['b'])
> '{"b":3}'



Agar funksiya bo'lsa, u orqali biz field'larni filter qilishimiz mumkin:


> JSON.stringify(
{ a: 5, b: 3 },
(key, value) =>
key == 'a'
? 10
: value
)
> '{"a":10,"b":3}'




2. space - bu parametr orqali obyektimizni indentatsiya qilishimiz mumkin. Masalan space parametri 2 ga teng bo'lsa, natija quydagicha bo'ladi:


> var obj = { name: "Tony", status: { rank : 1, type: "Avenger"}}

> console.log(JSON.stringify(
obj,
undefined,
2
))

{
"name": "Tony",
"status": {
"rank": 1,
"type": "Avenger"
}
}

#js #tips #jsdaily

BY Brogrammist


Share with your friend now:
tgoop.com/brogrammist/17

View MORE
Open in Telegram


Telegram News

Date: |

Hui said the messages, which included urging the disruption of airport operations, were attempts to incite followers to make use of poisonous, corrosive or flammable substances to vandalize police vehicles, and also called on others to make weapons to harm police. Those being doxxed include outgoing Chief Executive Carrie Lam Cheng Yuet-ngor, Chung and police assistant commissioner Joe Chan Tung, who heads police's cyber security and technology crime bureau. A Telegram channel is used for various purposes, from sharing helpful content to implementing a business strategy. In addition, you can use your channel to build and improve your company image, boost your sales, make profits, enhance customer loyalty, and more. Polls Co-founder of NFT renting protocol Rentable World emiliano.eth shared the group Tuesday morning on Twitter, calling out the "degenerate" community, or crypto obsessives that engage in high-risk trading.
from us


Telegram Brogrammist
FROM American