<?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[What is Reverse object hierarchy]]></title><description><![CDATA[<p dir="auto">is there any way to reverse the object in js?</p>
<pre><code>const initObject = { 
  value: 5,
  next: {
   value: 10,
   next: {
     value: 15
     next: null
   }
  },
}

//expected result

const newObject = {
  value: 15,
  next: {
    value: 10,
    next: {
      value: 5,
      next: null
    }
  }
}

</code></pre>
<p dir="auto">need to a function, but struggling hard.<br />
I tried to find the object depth-first and then make a founded amount of iterations for … in … inside the object but don’t know how to rewrite the new one</p>
]]></description><link>https://community.secnto.com//topic/2094/what-is-reverse-object-hierarchy</link><generator>RSS for Node</generator><lastBuildDate>Mon, 08 Jun 2026 22:41:46 GMT</lastBuildDate><atom:link href="https://community.secnto.com//topic/2094.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 02 Dec 2020 12:12:15 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to What is Reverse object hierarchy on Wed, 02 Dec 2020 12:13:20 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/maria-irshad" aria-label="Profile: maria-irshad">@<bdi>maria-irshad</bdi></a> said in <a href="/post/6166">What is Reverse object hierarchy</a>:</p>
<blockquote>
<p dir="auto">is there any way to reverse the object in js?</p>
<pre><code>const initObject = { 
  value: 5,
  next: {
   value: 10,
   next: {
     value: 15
     next: null
   }
  },
}

//expected result

const newObject = {
  value: 15,
  next: {
    value: 10,
    next: {
      value: 5,
      next: null
    }
  }
}

</code></pre>
<p dir="auto">need to a function, but struggling hard.<br />
I tried to find the object depth-first and then make a founded amount of iterations for … in … inside the object but don’t know how to rewrite the new one</p>
</blockquote>
<p dir="auto"><strong>Try this</strong></p>
<pre><code>const initObject = { 
  value: 5,
  next: {
   value: 10,
   next: {
     value: 15,
     next: null
   }
  }
}

const getValues = ({ value, next }) =&gt;
  next 
    ? [value, ...getValues(next)] 
    : [value]

const createObject = values =&gt; 
  values.reduce((next, value) =&gt; ({ value, next }), null)

const output = createObject(getValues(initObject))

console.log(output)
</code></pre>
]]></description><link>https://community.secnto.com//post/6167</link><guid isPermaLink="true">https://community.secnto.com//post/6167</guid><dc:creator><![CDATA[zaasmi]]></dc:creator><pubDate>Wed, 02 Dec 2020 12:13:20 GMT</pubDate></item><item><title><![CDATA[Reply to What is Reverse object hierarchy on Wed, 02 Dec 2020 12:15:39 GMT]]></title><description><![CDATA[<p dir="auto"><img src="https://i.imgur.com/rNceJPb.gif" alt="f7dcfc32-36e3-440c-969d-f3f7cfe2e3cf-image.gif" class=" img-fluid img-markdown" /><br />
<a href="https://i.stack.imgur.com/lyfji.gif" target="_blank" rel="noopener noreferrer nofollow ugc">Reff</a></p>
]]></description><link>https://community.secnto.com//post/6168</link><guid isPermaLink="true">https://community.secnto.com//post/6168</guid><dc:creator><![CDATA[zaasmi]]></dc:creator><pubDate>Wed, 02 Dec 2020 12:15:39 GMT</pubDate></item><item><title><![CDATA[Reply to What is Reverse object hierarchy on Wed, 02 Dec 2020 12:13:20 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/maria-irshad" aria-label="Profile: maria-irshad">@<bdi>maria-irshad</bdi></a> said in <a href="/post/6166">What is Reverse object hierarchy</a>:</p>
<blockquote>
<p dir="auto">is there any way to reverse the object in js?</p>
<pre><code>const initObject = { 
  value: 5,
  next: {
   value: 10,
   next: {
     value: 15
     next: null
   }
  },
}

//expected result

const newObject = {
  value: 15,
  next: {
    value: 10,
    next: {
      value: 5,
      next: null
    }
  }
}

</code></pre>
<p dir="auto">need to a function, but struggling hard.<br />
I tried to find the object depth-first and then make a founded amount of iterations for … in … inside the object but don’t know how to rewrite the new one</p>
</blockquote>
<p dir="auto"><strong>Try this</strong></p>
<pre><code>const initObject = { 
  value: 5,
  next: {
   value: 10,
   next: {
     value: 15,
     next: null
   }
  }
}

const getValues = ({ value, next }) =&gt;
  next 
    ? [value, ...getValues(next)] 
    : [value]

const createObject = values =&gt; 
  values.reduce((next, value) =&gt; ({ value, next }), null)

const output = createObject(getValues(initObject))

console.log(output)
</code></pre>
]]></description><link>https://community.secnto.com//post/6167</link><guid isPermaLink="true">https://community.secnto.com//post/6167</guid><dc:creator><![CDATA[zaasmi]]></dc:creator><pubDate>Wed, 02 Dec 2020 12:13:20 GMT</pubDate></item></channel></rss>