<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[gelöst-JS-Inhalt einer Variablen als Variable JSON]]></title><description><![CDATA[<p dir="auto">hätte eine frage .bzw bitte</p>
<p dir="auto">ich habe eine json-variable, die  man so abfragt:</p>
<p dir="auto">var x = resp.data[0].hostname<br />
var x= resp.data[0].name</p>
<p dir="auto">ich wurde gerne das ".hostname" oder ".name" variable halten - also abhängig von einer dritten variablen die auf true oder false gesetzt wird<br />
-&gt; ist diese dritte variable true brauche ich :    resp.data[0].name<br />
-&gt;ist diese dritte variable falsch brauche ich :    resp.data[0].hostname</p>
<p dir="auto">wie geht sowas ?</p>
]]></description><link>https://forum.iobroker.net/topic/25027/gelöst-js-inhalt-einer-variablen-als-variable-json</link><generator>RSS for Node</generator><lastBuildDate>Tue, 16 Jun 2026 02:55:59 GMT</lastBuildDate><atom:link href="https://forum.iobroker.net/topic/25027.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 11 Sep 2019 17:35:42 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to gelöst-JS-Inhalt einer Variablen als Variable JSON on Wed, 11 Sep 2019 18:28:34 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/mic" aria-label="Profile: Mic">@<bdi>Mic</bdi></a></p>
<p dir="auto">danke für deine antwort - war nicht weit weg von der lösung - ich hatte noch punkt drin - und damit gehts nicht</p>
<pre><code>// Alternative A
........
log(resp.data[0].[myVar]);
</code></pre>
<p dir="auto">vielen dank nochmals-  funktioniert im ersten schnelltest</p>
]]></description><link>https://forum.iobroker.net/post/299332</link><guid isPermaLink="true">https://forum.iobroker.net/post/299332</guid><dc:creator><![CDATA[liv-in-sky]]></dc:creator><pubDate>Wed, 11 Sep 2019 18:28:34 GMT</pubDate></item><item><title><![CDATA[Reply to gelöst-JS-Inhalt einer Variablen als Variable JSON on Wed, 11 Sep 2019 18:22:05 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/liv-in-sky" aria-label="Profile: liv-in-sky">@<bdi>liv-in-sky</bdi></a><br />
Zunächst: ich denke wir sollten Variablen immer per <code>let</code> deklarieren, und nicht mehr per <code>var</code>, macht das Debugging etc. viel einfacher: <a href="https://love2dev.com/blog/javaScript-var-let-const/" rel="nofollow ugc">https://love2dev.com/blog/javaScript-var-let-const/</a><br />
Das Block-Level-Scoping dank <code>let</code> hat mich schon vor einigen Fehlern bewahrt.</p>
<p dir="auto">Zu deiner Frage:<br />
Du verwendest die Punkt-Notation. Genau so kannst du das auch so machen:</p>
<pre><code>// Alternative A
log(resp.data[0].hostname);
// Alternative B
let myVar = 'hostname';
log(resp.data[0][myVar]);
</code></pre>
]]></description><link>https://forum.iobroker.net/post/299327</link><guid isPermaLink="true">https://forum.iobroker.net/post/299327</guid><dc:creator><![CDATA[Mic]]></dc:creator><pubDate>Wed, 11 Sep 2019 18:22:05 GMT</pubDate></item></channel></rss>