代码拉取完成,页面将自动刷新
<p>Given an object or array <code>obj</code>, return a <strong>compact object</strong>. A <strong>compact object</strong> is the same as the original object, except with keys containing <strong>falsy</strong> values removed. This operation applies to the object and any nested objects. Arrays are considered objects where the indices are keys. A value is considered <strong>falsy</strong> when <code>Boolean(value)</code> returns <code>false</code>.</p>
<p>You may assume the <code>obj</code> is the output of <code>JSON.parse</code>. In other words, it is valid JSON.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> obj = [null, 0, false, 1]
<strong>Output:</strong> [1]
<strong>Explanation:</strong> All falsy values have been removed from the array.
</pre>
<p><strong class="example">Example 2:</strong></p>
<pre>
<strong>Input:</strong> obj = {"a": null, "b": [false, 1]}
<strong>Output:</strong> {"b": [1]}
<strong>Explanation:</strong> obj["a"] and obj["b"][0] had falsy values and were removed.</pre>
<p><strong class="example">Example 3:</strong></p>
<pre>
<strong>Input:</strong> obj = [null, 0, 5, [0], [false, 16]]
<strong>Output:</strong> [5, [], [16]]
<strong>Explanation:</strong> obj[0], obj[1], obj[3][0], and obj[4][0] were falsy and removed.
</pre>
<p> </p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>obj</code> is a valid JSON object</li>
<li><code>2 <= JSON.stringify(obj).length <= 10<sup>6</sup></code></li>
</ul>
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。