Skip to content
Advertisement

Create another data for single data in array

I’m doing a matchmaking system where 2 players with the same level will be matched (Joined in 1 array). My target is how can I make the player who has no match to have a 2nd data in array?

JavaScript

The example I provided is when a player who doesn’t have a match, there should be another data that produces “nm” which means no match.

I have provided an image of my target for better visualization of my problem and target. Thank you so much

enter image description here

Script:

JavaScript

json.stringify

JavaScript

Advertisement

Answer

If your target is only to add input for nm you can check if the JSON Array length is 1 or not . If its 1 it means there is only one match found so you can add other match with nm values inside val.forEach(.. .

Demo Code:

JavaScript
JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement