{"id":260460,"date":"2023-01-28T08:09:52","date_gmt":"2023-01-28T00:09:52","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=260460"},"modified":"2022-12-27T23:11:21","modified_gmt":"2022-12-27T15:11:21","slug":"arrify-math-linux","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/arrify-math-linux.html","title":{"rendered":"\u89e3\u6790arrify \u8f6c\u6570\u7ec4\u5b9e\u73b0\u793a\u4f8b\u6e90\u7801"},"content":{"rendered":"
\u5bfc\u8bfb<\/td>\n | \u8fd9\u7bc7\u6587\u7ae0\u4e3b\u8981\u4e3a\u5927\u5bb6\u4ecb\u7ecd\u4e86arrify \u8f6c\u6570\u7ec4\u5b9e\u73b0\u793a\u4f8b\u6e90\u7801\u89e3\u6790\uff0c\u6709\u9700\u8981\u7684\u670b\u53cb\u53ef\u4ee5\u501f\u9274\u53c2\u8003\u4e0b\uff0c\u5e0c\u671b\u80fd\u591f\u6709\u6240\u5e2e\u52a9\uff0c\u795d\u5927\u5bb6\u591a\u591a\u8fdb\u6b65\uff0c\u65e9\u65e5\u5347\u804c\u52a0\u85aa<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n \u5b66\u4e60\u76ee\u6807<\/strong><\/div>\n \u62c9\u53d6\u6e90\u7801<\/strong><\/div>\n \u8fdb\u5165\u5230 arrify \u4ed3\u5e93\u4e0b\uff0c\u4f7f\u7528 CodeSpace \u514b\u9686\u4e00\u4efd\u9879\u76ee\u3002<\/p>\n \u9879\u76ee\u76ee\u5f55\u5982\u56fe\uff1a<\/p>\n <\/p>\n \u5ffd\u7565\u6389\u4e00\u4e9b\u914d\u7f6e\u6587\u4ef6\uff0c\u5404\u4e2a\u6587\u4ef6\u7684\u529f\u80fd\u5982\u4e0b\uff1a<\/p>\n \u5206\u6790\u6e90\u7801<\/strong><\/div>\n arrify\u51fd\u6570\u53ef\u4ee5\u63a5\u53d7\u4e00\u4e2a\u503c\uff0c\u5e76\u8fd4\u56de\u4e00\u4e2a\u5305\u542b\u8be5\u503c\u7684\u6570\u7ec4,\u6839\u636e\u4f20\u5165\u4e0d\u540c\u7c7b\u578b\u7684\u503c\u8fd4\u56de\u4e0d\u540c\u7684\u7ed3\u679c\u3002<\/p>\n export default function arrify(value) {\r\n \/\/ \u5982\u679c\u4f20\u5165\u7684\u503c\u662f null \u6216 undefined\uff0c\u51fd\u6570\u4f1a\u8fd4\u56de\u4e00\u4e2a\u7a7a\u6570\u7ec4\u3002\r\n if (value === null || value === undefined) {\r\n return [];\r\n }\r\n \/\/ \u5982\u679c\u4f20\u5165\u7684\u503c\u672c\u8eab\u5c31\u662f\u4e00\u4e2a\u6570\u7ec4\uff0c\u51fd\u6570\u4f1a\u76f4\u63a5\u8fd4\u56de\u8fd9\u4e2a\u6570\u7ec4\r\n if (Array.isArray(value)) {\r\n return value;\r\n }\r\n \/\/ \u5982\u679c\u4f20\u5165\u7684\u503c\u662f\u4e00\u4e2a\u5b57\u7b26\u4e32\uff0c\u51fd\u6570\u4f1a\u8fd4\u56de\u4e00\u4e2a\u5305\u542b\u8be5\u5b57\u7b26\u4e32\u7684\u6570\u7ec4\u3002\r\n if (typeof value === 'string') {\r\n return [value];\r\n }\r\n \/\/ \u5982\u679c\u4f20\u5165\u7684\u503c\u662f\u4e00\u4e2a\u53ef\u8fed\u4ee3\u5bf9\u8c61\uff0c\u51fd\u6570\u4f1a\u8fd4\u56de\u4e00\u4e2a\u5305\u542b\u8be5\u5bf9\u8c61\u6240\u6709\u5143\u7d20\u7684\u6570\u7ec4\u3002\r\n if (typeof value[Symbol.iterator] === 'function') {\r\n return [...value];\r\n }\r\n \/\/ \u5982\u679c\u4f20\u5165\u7684\u503c\u65e2\u4e0d\u662f null\/undefined\uff0c\u4e5f\u4e0d\u662f\u4e00\u4e2a\u6570\u7ec4\/\u5b57\u7b26\u4e32\/\u53ef\u8fed\u4ee3\u5bf9\u8c61\uff0c\u51fd\u6570\u4f1a\u8fd4\u56de\u4e00\u4e2a\u5305\u542b\u8be5\u503c\u7684\u6570\u7ec4\u3002\r\n return [value];\r\n}<\/pre>\n |