{ "data": { "question": { "questionId": "2864", "questionFrontendId": "2727", "categoryTitle": "JavaScript", "boundTopicId": 2302689, "title": "Is Object Empty", "titleSlug": "is-object-empty", "content": "
Given an object or an array, return if it is empty.
\n\nYou may assume the object or array is the output of JSON.parse
.
\n
Example 1:
\n\n\nInput: obj = {"x": 5, "y": 42}\nOutput: false\nExplanation: The object has 2 key-value pairs so it is not empty.\n\n\n
Example 2:
\n\n\nInput: obj = {}\nOutput: true\nExplanation: The object doesn't have any key-value pairs so it is empty.\n\n\n
Example 3:
\n\n\nInput: obj = [null, false, 0]\nOutput: false\nExplanation: The array has 3 elements so it is not empty.\n\n\n
\n
Constraints:
\n\nobj
is a valid JSON object or array2 <= JSON.stringify(obj).length <= 105
\nCan you solve it in O(1) time?", "translatedTitle": "判断对象是否为空", "translatedContent": "
给定一个对象或数组,判断它是否为空。
\n\n你可以假设对象或数组是通过 JSON.parse
解析得到的。
\n\n
示例 1:
\n\n\n输入:obj = {\"x\": 5, \"y\": 42}\n输出:false\n解释:这个对象有两个键值对,所以它不为空。\n\n\n
示例 2:
\n\n\n输入:obj = {}\n输出:true\n解释:这个对象没有任何键值对,所以它为空。\n\n\n
示例 3:
\n\n\n输入:obj = [null, false, 0]\n输出:false\n解释:这个数组有 3 个元素,所以它不为空。\n\n\n
\n\n
提示:
\n\nobj
是一个有效的 JSON 对象或数组2 <= JSON.stringify(obj).length <= 105
\n你可以在 O(1) 时间复杂度内解决这个问题吗?", "isPaidOnly": false, "difficulty": "Easy", "likes": 0, "dislikes": 0, "isLiked": null, "similarQuestions": "[]", "contributors": [], "langToValidPlayground": "{\"cpp\": true, \"java\": true, \"python\": true, \"python3\": true, \"mysql\": false, \"mssql\": false, \"oraclesql\": false, \"c\": false, \"csharp\": false, \"javascript\": false, \"typescript\": false, \"bash\": false, \"php\": false, \"swift\": false, \"kotlin\": false, \"dart\": false, \"golang\": false, \"ruby\": false, \"scala\": false, \"html\": false, \"pythonml\": false, \"rust\": false, \"racket\": false, \"erlang\": false, \"elixir\": false, \"pythondata\": false, \"react\": false, \"vanillajs\": false, \"postgresql\": false}", "topicTags": [], "companyTagStats": null, "codeSnippets": [ { "lang": "JavaScript", "langSlug": "javascript", "code": "/**\n * @param {Object|Array} obj\n * @return {boolean}\n */\nvar isEmpty = function(obj) {\n \n};", "__typename": "CodeSnippetNode" }, { "lang": "TypeScript", "langSlug": "typescript", "code": "type JSONValue = null | boolean | number | string | JSONValue[] | { [key: string]: JSONValue };\ntype Obj = Record
\\u7248\\u672c\\uff1a \\u60a8\\u7684\\u4ee3\\u7801\\u5728\\u6267\\u884c\\u65f6\\u5c06\\u5e26\\u4e0a lodash.js<\\/a> \\u5e93\\u5df2\\u7ecf\\u9ed8\\u8ba4\\u88ab\\u5305\\u542b\\u3002<\\/p>\\r\\n\\r\\n \\u5982\\u9700\\u4f7f\\u7528\\u961f\\u5217\\/\\u4f18\\u5148\\u961f\\u5217\\uff0c\\u60a8\\u53ef\\u4f7f\\u7528 datastructures-js\\/priority-queue@5.3.0<\\/a> \\u548c datastructures-js\\/queue@4.2.1<\\/a>\\u3002<\\/p>\"],\"typescript\":[\"TypeScript\",\" TypeScript 5.1.6<\\/p>\\r\\n\\r\\n Compile Options: --alwaysStrict --strictBindCallApply --strictFunctionTypes --target ES2022<\\/p>\\r\\n\\r\\n lodash.js<\\/a> \\u5e93\\u5df2\\u7ecf\\u9ed8\\u8ba4\\u88ab\\u5305\\u542b\\u3002<\\/p>\\r\\n\\r\\n \\u5982\\u9700\\u4f7f\\u7528\\u961f\\u5217\\/\\u4f18\\u5148\\u961f\\u5217\\uff0c\\u60a8\\u53ef\\u4f7f\\u7528 datastructures-js\\/priority-queue@5.3.0<\\/a> \\u548c datastructures-js\\/queue@4.2.1<\\/a>\\u3002<\\/p>\"]}",
"book": null,
"isSubscribed": false,
"isDailyQuestion": false,
"dailyRecordStatus": null,
"editorType": "CKEDITOR",
"ugcQuestionId": null,
"style": "LEETCODE",
"exampleTestcases": "{\"x\": 5, \"y\": 42}\n{}\n[null, false, 0]",
"__typename": "QuestionNode"
}
}
}Node.js 16.13.2<\\/code><\\/p>\\r\\n\\r\\n
--harmony<\\/code> \\u6807\\u8bb0\\u6765\\u5f00\\u542f \\u65b0\\u7248ES6\\u7279\\u6027<\\/a>\\u3002<\\/p>\\r\\n\\r\\n