Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

某公司 1 到 12 月份的销售额存在一个对象里面 #44

Open
lovelmh13 opened this issue Feb 23, 2020 · 0 comments
Open

某公司 1 到 12 月份的销售额存在一个对象里面 #44

lovelmh13 opened this issue Feb 23, 2020 · 0 comments

Comments

@lovelmh13
Copy link
Owner

lovelmh13 commented Feb 23, 2020

原题

如下:{1:222, 2:123, 5:888},请把数据处理为如下结构:[222, 123, null, null, 888, null, null, null, null, null, null, null]。

function mapData(obj) {
	let month = new Array(12).fill(null);
	const monthKeys = Object.keys(obj);
	monthKeys.map((key) => {
		month[key-1] = obj[key]
	});
	return month;
}
mapData({1:222, 2:123, 5:888});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant