Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • Aug 17 09:32
    User @bjorno43 unbanned @linkin-park
  • Jun 20 21:19
    @bjorno43 banned @shenerd140
  • Apr 25 17:13
    @mstellaluna banned @cmal
  • Jan 08 22:05
    @mstellaluna banned @dertiuss323
  • Nov 07 2018 04:42
    User @texas2010 unbanned @ows-ali
  • Nov 02 2018 16:25
    @texas2010 banned @ows-ali
  • Oct 12 2018 05:50
    @bjorno43 banned @NACH74
  • Oct 05 2018 23:02
    @mstellaluna banned @JomoPipi
  • Sep 16 2018 12:21
    @bjorno43 banned @yash-kedia
  • Sep 16 2018 12:16
    @bjorno43 banned @vnikifirov
  • Sep 05 2018 08:12
    User @bjorno43 unbanned @androuino
  • Sep 05 2018 07:38
    @bjorno43 banned @androuino
  • Aug 23 2018 16:57
    User @bjorno43 unbanned @rahuldkjain
  • Aug 23 2018 16:23
    @bjorno43 banned @rahuldkjain
  • Jul 29 2018 14:13
    User @bjorno43 unbanned @jkyereh
  • Jul 29 2018 01:00
    @bjorno43 banned @jkyereh
  • Jul 10 2018 22:09
    @bjorno43 banned @manafn
  • Jul 06 2018 15:20
    @texas2010 banned @imlegend19
  • Jul 03 2018 12:28
    @bjorno43 banned @vbvmatta
  • Jun 29 2018 13:54
    @bjorno43 banned @OGTechnoBoy
Jack Lyons
@JackEdwardLyons
so to access the first object you would write jsonArray[0]
for all objects
iwould use a forEach loop
one second
how many inputs do you have?
RakeshNerkar
@Rakesh18754
only one array which can have n number of objects
@JackEdwardLyons but all have the same sructure
Jack Lyons
@JackEdwardLyons
this jsonArray var jsonArray = [{ "tagValueName": "PCI", "tagValueId": 1, "priorityAlertsCount": 20, "investigationAlertsCount": 140, "incidentAlertsCount": 100, "otherAlertsCount": 40 }, { "tagValueName": "ABC", "tagValueId": 2, "priorityAlertsCount": 100, "investigationAlertsCount": 60, "incidentAlertsCount": 20, "otherAlertsCount": 20 }];
is different to the below arrays, does that matter?
RakeshNerkar
@Rakesh18754

@JackEdwardLyons

var jsonInputArray = [{
            "tagValueName": "PCI",     
            "tagValueId": 1,
            "priorityAlertsCount": 20,
            "investigationAlertsCount": 140,
            "incidentAlertsCount": 100,
            "otherAlertsCount": 40
        }, {
            "tagValueName": "ABC",
            "tagValueId": 2,
            "priorityAlertsCount": 100,
            "investigationAlertsCount": 60,
            "incidentAlertsCount": 20,
            "otherAlertsCount": 20
        }];

output should be

var jsonData = [{
                "tagValueName" : "PCI",
                "type": "priorityAlertsCount",
                "count": "20",
            },
            {
                "tagValueName" : "PCI",
                "type": "investigationAlertsCount",
                "count": "140",
            },
            {
                "tagValueName" : "PCI",
                "type": "incidentAlertsCount",
                "count": "100",
            },
            {
                "tagValueName" : "PCI",
                "type": "otherAlertsCount",
                "count": "40",
            },{
                "tagValueName" : "ABC",
                "type": "priorityAlertsCount",
                "count": "100",
            },{
                "tagValueName" : "ABC",
                "type": "investigationAlertsCount",
                "count": "60",
            }];
Jack Lyons
@JackEdwardLyons
weird..
what do you need this for?
RakeshNerkar
@Rakesh18754
@JackEdwardLyons actually i am trying to plot a chart
and my chart requires data in that specific format
Jack Lyons
@JackEdwardLyons
ok, well im probably the wrong person to ask, this is weird how the above array is so varied from the second array, in terms of key value pairs... they are totally different
JiaLe Guo
@gabygoole
In ikipedia
In Wikipedia Viewer´╝î what kind of thing should I learn?
Adi2Point0
@Adi2Point0
@Rakesh18754
var jsonData = [];

var keysToDrop = ['tagValueName', 'tagValueId'];

jsonArray.forEach(function(json){
  Object.keys(json).forEach(function(key){
    if(keysToDrop.indexOf(key) === -1){
      jsonData.push({
        tagValueName : json.tagValueName,
        type : key,
        count : json[key]
      })
    }
  });
});
tommy
@tommygebru
@khaduch yeah is it possible to get the text? or is that not available through the api?
Thomas Swatland
@swatbone85
Hi all, I'm trying to create a button that toggles through 2 alternating options. This is my code: $("h3 a").on("click", function() { counter += 1; console.log(counter % 2); /* switch(counter % 2) { case 0: $("h3").html(Math.round(data.main.temp * 1.8 + 32) + "<a href='#'>&#176F</a>"); case 1: $("h3").html(Math.round(data.main.temp) + "<a id='temp' href='#'>&#176C</a>"); } */ });
Thing is, the code inside the comments only runs once. Any pointers?
$("h3 a").on("click", function() {
          counter += 1;
          console.log(counter % 2);
          /*
          switch(counter % 2) {
            case 0:
            $("h3").html(Math.round(data.main.temp * 1.8 + 32) + "<a href='#'>&#176F</a>");
            case 1:
            $("h3").html(Math.round(data.main.temp) + "<a id='temp' href='#'>&#176C</a>");
          }
          */
        });
Thomas Swatland
@swatbone85
Anyone?
Abhishek Kumar
@Mr-Kumar-Abhishek
@swatbone85 I don't get what are you trying to do but..... why aren't there break; after switch cases ??
@swatbone85 uh.. nevermind seems those are commented out ... hard to fiqure via IRC
@swatbone85 oh, so you were asking about commented out code lol
@swatbone85 so my question remains ~
Thomas Swatland
@swatbone85
@Mr-Kumar-Abhishek Yes, because the console.log works fine, but when I remove the comments the code only runs once...
Abhishek Kumar
@Mr-Kumar-Abhishek
@swatbone85 so my question remains why not using break; after switch cases ??
Thomas Swatland
@swatbone85
@Mr-Kumar-Abhishek Because I forgot them, and added them after. Thanks for that! The code still only runs once though...
CamperBot
@camperbot
swatbone85 sends brownie points to @mr-kumar-abhishek :sparkles: :thumbsup: :sparkles:
:cookie: 413 | @mr-kumar-abhishek |http://www.freecodecamp.com/mr-kumar-abhishek
Abhishek Kumar
@Mr-Kumar-Abhishek
@swatbone85 hmm... okay so after breaks what is the error here...
@swatbone85 is this over codepen ??
Thomas Swatland
@swatbone85
@Mr-Kumar-Abhishek I'm working on the local weather challenge. I'm trying to alternate between C and F, so the button needs to toggle between the two. No this is pasted from Atom
Abhishek Kumar
@Mr-Kumar-Abhishek
@swatbone85 i see.. let me fiddle it around https://jsfiddle.net/ then..
tommy
@tommygebru
is it possible to make a getjson call within another getjson call?
Thomas Swatland
@swatbone85
@tommygebru I put a .ajax inside the success function of another .ajax and it worked fine!
@tommygebru So I reckon the same should work for getJSON :)
tommy
@tommygebru
ok :smile:
Adi2Point0
@Adi2Point0
@tommygebru : Yes you can.
tommy
@tommygebru
im really confused right now though
regStreamers.map(function(val) {
$.getJSON(twitchAPI + streams + val + callback, function(data1) {
            if (data1.status === 404) {
                $(".wrap").append("<div class='streamers offline delete'><span class='i-fix'><i class='ion-close'></i><img src='https://68.media.tumblr.com/2bab580406f69a3ff294bd0782d83c5a/tumblr_ohkte1EwLM1sj6gx1o1_540.png'></span><div class='info'><span>" + val + " </span><span>does not exist</span></div></div>");
                $(".offline i").click(function() {
                    $(this.closest(".delete")).remove();
  });
            } else if (data1.status === null) {
                $.getJSON(twitchAPI + channels + val + callback, function(data2) {
                    $(".wrap").append("<a href=" + data2.url + "><div class='streamers offline'><img src='https://68.media.tumblr.com/2bab580406f69a3ff294bd0782d83c5a/tumblr_ohkte1EwLM1sj6gx1o1_540.png'><div class='info'><span>" + val + " </span><span>is currently offline</span></div></div></a>");
                });
            } else {
                $(".wrap").append("<a href=" + data1.stream.channel.url + "><div class='streamers online'><img src=" + valData.stream.channel.logo + "><div class='info'><span>" + val + " </span><span class='game'>streaming " + valData.stream.game + "</span><span>" + valData.stream.viewers + " viewers</span></div></div></a>");
            } //ELSE
        }); //data1
});//map
Abhishek Kumar
@Mr-Kumar-Abhishek
@swatbone85 probably your html structure messes around after the first run your script
Thomas Swatland
@swatbone85
@Mr-Kumar-Abhishek Yeah that may be it. I'll dig a little deeper, thank you!
CamperBot
@camperbot
swatbone85 sends brownie points to @mr-kumar-abhishek :sparkles: :thumbsup: :sparkles:
:warning: swatbone85 already gave mr-kumar-abhishek points
Abhishek Kumar
@Mr-Kumar-Abhishek
@swatbone85 after js changes your html it should still maintain <h3><a>your text</a></h3> no texts between h3 and a
@swatbone85 I making js fiddle to show you ...
tommy
@tommygebru
@Adi2Point0 @swatbone85 basically i was able to get all working but when i mixed the jsons together only 2/3 conditions would execute code not all 3 though...
data1 is pulling from this json https://wind-bow.hyperdev.space/twitch-api/streams/ESL_SC2
data2 is pulling from this json https://wind-bow.hyperdev.space/twitch-api/channels/ESL_SC2
I want to be able to create anchor links and wrap divs...
however because some streamers are offline... I have to change the api call to get the url from a different json
tommy
@tommygebru
oops ok i fixed some of it
but still the same problem
regStreamers.map(function(val) {
        $.getJSON(twitchAPI + streams + val + callback, function(data1) {
            if (data1.status === 404) {
                $(".wrap").append("<div class='streamers offline delete'><span class='i-fix'><i class='ion-close'></i><img src='https://68.media.tumblr.com/2bab580406f69a3ff294bd0782d83c5a/tumblr_ohkte1EwLM1sj6gx1o1_540.png'></span><div class='info'><span>" + val + " </span><span>does not exist</span></div></div>");
                $(".offline i").click(function() {
                    $(this.closest(".delete")).remove();
                });
            } else if (data1.status === null) {
                $.getJSON(twitchAPI + channels + val + callback, function(data2) {
                    $(".wrap").append("<a href=" + data2.url + "><div class='streamers offline'><img src='https://68.media.tumblr.com/2bab580406f69a3ff294bd0782d83c5a/tumblr_ohkte1EwLM1sj6gx1o1_540.png'><div class='info'><span>" + val + " </span><span>is currently offline</span></div></div></a>");
                });//data2
            } else {
                $(".wrap").append("<a href=" + data1.stream.channel.url + "><div class='streamers online'><img src=" + data1.stream.channel.logo + "><div class='info'><span>" + val + " </span><span class='game'>streaming " + data1.stream.game + "</span><span>" + data1.stream.viewers + " viewers</span></div></div></a>");
            } //ELSE
        }); //data1
    }); //map
Adi2Point0
@Adi2Point0
@tommygebru I wish I could help. But the APIs seem to have been blocked at my work proxy